Redis cache penetration, breakdown cache, the cache avalanches interpretation of the classic problems

Since the basic reading the stand-alone part of "Redis Design and Implementation" in, so you can see some of the interview questions often asked, with a question to learn, so that efficiency will be higher.

Cache penetration

Brief introduction

Cache penetration (cache breakdown) represents a malicious user to request a lot of data that does not exist, because the database did not, certainly not in the cache, resulting in a short time these requests directly landed on the database, resulting in a database exception.

solution

1: Cache null

    The reason why penetration occurs, it is because the cache does not store the key null data. Leading to every query to the database to go. So we can think that these key value is set to null to throw cache inside. Back then query this key time of the request, direct return null. So as not to use the database to walk around, but do not forget to set the expiration time.

2: Bloom filter

    BloomFilter similar to a hash set, to determine if an element (Key) is present in a set, this solution can be added to a first embodiment, prior to adding the buffer layer BloomFilter, the first query time Key to BloomFilter to query whether there is, if there is no direct return, there is a walk check caching ---> DB search process.

plan selection

Features: Key more, less repetitive requests:

    Against malicious attacks, attacks brought over a large number of Key does not exist, then we will adopt the first option to cache large amounts of data does not exist Key. So the second option;

Features: Key dummy data is limited, relatively high repetition rate:

    The first embodiment may be employed;

Cache breakdown

Cache avalanche

Dual write consistency

Concurrent competition

References:

https://juejin.im/post/5c9a67ac6fb9a070cb24bf34

Guess you like

Origin www.cnblogs.com/zpcoding/p/12461961.html