Redis interview focus ------ from the dark horse

insert image description here
insert image description here
Cache problem The three brothers are caused by the fact that all the requests hit the database for different reasons

What is cache penetration?

Cache penetration refers to querying a data, which does not exist in redis and MySQL. That is to query a data that does not exist , causing each request to reach the database, causing a lot of pressure on the data.
Solution:
1. Cache an empty data when querying a non-existent data, so that the request will only check the library once, and transfer the traffic to redis Advantages: It is simple and convenient to implement Disadvantages
:
Consuming memory, which may cause short-term data Inconsistency, increased pressure on the cache
2. Bloom filter
insert image description here
insert image description here
What is cache breakdown?
Cache breakdown: A hotspot key has expired , and data synchronization is slow, causing all requests to reach the database.
Solution
1. Mutual exclusion lock
2. Logical expiration
insert image description here

What is cache avalanche?

Cache avalanche means that a large number of keys expire at the same time during a certain period of time, causing all requests to reach the database
solution
insert image description here

How to synchronize data between redis and MySQL?

insert image description here

If it is strong consistency (CP): double-write consistency (modify the cache after modifying the database), the data stored in redis must read more and write less. When modifying data, using read-write locks is a good choice.
Features: strong consistency, low performance, code intrusion is too high
insert image description here
insert image description here

If it is availability (AP): mq (the vast majority of data synchronization, AP implementation can use mq, allowing short-term data inconsistency, to achieve final consistency), canal
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_56533553/article/details/130366463