Bloom filter (BloomFilter)

A. Redis of the three major issues

name problem Solution
Cache penetration Query the data does not exist 布隆过滤器
Cache breakdown A key cache invalidation Mutex
Cache avalanche Key simultaneous failure of multiple cache Failure time + random time

II. Principle of the Bloom filter

The bottom layer is called a bit vector or a binary bit array, the data bit stored in the non-0 or 1.
Here Insert Picture Description
By hash function element is mapped onto the corresponding bit position, and this position is set to 1. The hash (element) = 2:
Here Insert Picture Description
When you want to query whether there is an element, the first element by a hash function mapping obtained bit position, and then determines the position of this bit is 0 or 1, if it is 0, then this element certainly does not exist, if it is 1, then the elements do not really exist (do you remember Daming Lake, the classic line: hash值相等,不一定是同一个对象;同一个对象,hash值一定相等).

III. Disadvantage Bloom filter

  • 真假难辨
Indeed shortcomings Explanation solve
Miscarriage of justice Get an element in the bit position, when the judge found that this position is 1, but in fact this element does not exist Separate storage element may be a miscarriage of justice
Delete wrong Two or more elements mapped to the same bit position, you want to delete a time, the 1 to 0, leading to other elements also finished Counting Bloom Filter
Published 70 original articles · won praise 4 · Views 6372

Guess you like

Origin blog.csdn.net/qq_44837912/article/details/104425408