Redis database topic 017---Introduction to cache penetration, breakdown, and avalanche

Redis cache penetration:

The basic flow of cache access

(1) The application accesses the cache, and if the data exists, the data is returned directly

(2) If the data does not exist in redis, then go to the database, the database query will directly return to the application, and the result will be written back to redis

(3) The data does not exist in redis, the database does not exist, and the return is empty. Generally speaking, a null value will not be written to redis. If the same data is requested repeatedly, cache penetration will occur.

The solution is to set a null value for this key and write to redis at the same time. The database will not be accessed the next time it is requested, but if a different key is requested each time, the key does not exist in the database at the same time. Then cache penetration will still occur in this way.

Therefore, the Bloom filter is introduced: first determine whether the key value exists, if it does not exist, then redis is not accessed, then a large number of requests can be intercepted, and the Bloom filter can meet this demand.

Bloom filter, Bloom Filter is proposed by Bloom in 1970, it is composed of a set of hash (Hash) function and a bit array. Bloom filters can be used to query whether an element exists in a collection, and the query result is one of the following:

This element may exist in this set.

This element must not exist in this set.

The advantage of Bloom filter is that the space efficiency and query time are much better than the general algorithm, but the disadvantage is that it has a certain misrecognition rate and difficulty in deletion.

Bloom filters are mainly used in practice to solve the problems of web URL deduplication, spam detection, judgment of duplicate elements in large collections, and cache breakdown. Bloom filters can only be added but not deleted. Centralized way of adding bloom filters.

Redis cache avalanche:

It is easy to happen when a large number of keys expire at the same time. Two situations: ①Direct avalanche at zero point ②Timelessness

The general direction of the final solution: fusing, current limiting, isolation

Temporary small plan: different keys set different timeouts

 

Redis cache breakdown:

Cache breakdown refers to a key that is very hot. It is constantly carrying large concurrency, and the large concurrency concentrates on accessing this point. When the key is invalid, the continuous large concurrency will break through the cache and directly request the database. It's like cutting a hole in an undamaged barrel

 

 

Guess you like

Origin blog.csdn.net/LB_Captain/article/details/114537219