Redis penetration breakdown avalanche

Three major problems of Redis cache penetration breakdown avalanche

1. Cache penetration

Cache penetration refers to the data that does not exist in the cache or the database, but users continue to initiate requests, such as data with an id of "-1" or data with an id that is particularly large and does not exist. At this time, the user is likely to be an attacker, and the attack will cause excessive pressure on the database.

solution:

  1. Create a data empty object, stored in the cache, so that the database will not be queried. Simple, easy to maintain, not effective.
  2. Solved using a Bloom filter. Difficult, difficult to maintain, effective.

2. Cache breakdown

Cache breakdown refers to data that is not in the cache but is in the database (usually the cache time expires). At this time, due to the large number of concurrent users, the read cache does not read the data at the same time, and at the same time go to the database to fetch data, causing pressure on the database Momentary increase, causing excessive pressure

solution:

  1. Set hotspot data to never expire.
  2. Lock with Redislock.

3. Cache Avalanche

Cache avalanche means that a large amount of data in the cache reaches the expiration time, and the query data volume is huge, causing excessive pressure on the database or even downtime. Different from the cache breakdown, the cache breakdown refers to concurrently querying the same piece of data, and the cache avalanche means that different data have expired, and many data cannot be found, so the database is checked.

solution:

  1. The expiration time of cached data is set randomly to prevent a large amount of data from being expired at the same time.
  2. If the cache database is deployed in a distributed manner, evenly distribute hotspot data in different cache databases.
  3. Set hotspot data to never expire.

Guess you like

Origin blog.csdn.net/weixin_40069439/article/details/108159350