Redis cache avalanche, penetration, breakdown

 Normal Process

 Execution flowchart

 cache breakdown

 solution

1. Never expires:

Some predictable popular products can be set to never expire, and some unpopular products can be set to expire. When the number of visits of unpopular products surges within a certain period of time, the expiration time can be changed to never expire.

2. Locking and queuing:

When the cache suddenly fails, only one thread is allowed to enter redis to query data. If there is no data in redis, it will query from the database and set it to redis. Later threads will get data from redis when they enter again.

 cache avalanche

 solution

1. Random invalidation time (solution for cache set expiration)

 

2. Make a cluster for redis in advance, and do a good job in sentinel mode (server downtime)

3. Do a good job in multiple computer rooms (the server suddenly loses power)

cache penetration

According to the normal program execution flow, cache penetration will not be caused. Only when a large number of requests access non-existing data, or malicious attacks, will cache penetration occur.

 solution

1. Parameter verification

Negative numbers or invalid parameters are filtered out, but cannot be completely eliminated.

2. Cache empty objects

On the basis of cache breakdown and cache avalanche, regardless of whether the database has this data, it is stored in redis, and a random expiration time is set (both to prevent avalanche and to prevent penetration)

 3. Bloom filter  

To put it bluntly, it is a data structure that is more efficient than list, set, and map, and takes up less space

Guess you like

Origin blog.csdn.net/xzxailh/article/details/128994758
Recommended