“This is the third day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”
Principle 1.
In the figure above, key1 and key2 hash the data multiple times and then modulo the data according to the length. If the scattered positions are 1, the data exists. If the scattered positions have 0, the data does not exist.Copy the code
2. Show
When a value exists in a Bloom filter, it may not exist; But when a value does not exist, then the value does not exist and has some error, but it is acceptableCopy the code
When the matching speed of Bloom filter is very fast and the memory usage is small, the error detection rate will increase. For example, when the declared space length/data length is too small, the error detection rate will also increase when the number of hash calculation is smallCopy the code
Bloom calculator
3. The application of
For example, what if a crawler needs to redo a link that has already been crawled? The database stores links that have been climbed. Where do you store those links? As time goes on and the amount of data becomes more and more how do you deal with efficiency? Cache penetration: when some malicious link background data does not exist, at this time the query data cache was killed and went to access the database, equivalent when the background database will not hold up, at this time for non-existent data can be directly discarded. The existing data is cached. That means existing data will also be put into bloom's filterCopy the code
4. Install
Address of 4.1.
Wget HTTP: / / https://codeload.github.com/RedisBloom/RedisBloom/tar.gz/refs/tags/v2.2.9 https://github.com/RedisBloom/RedisBloomCopy the code
4.2 unzip
The tar - XZVF RedisBloom - 2.2.9. Tar. GzCopy the code
Compile 4.3.
Switching the directory make produces the file: redisbloom.soCopy the code
4.4. Modify the Redis configuration file
4.5. Start
If the configuration file does not take effect during startup, specify the configuration file redis-server /etc/redis/redis.conf or redis-server -- loadModule The/etc/redis/RedisBloom - 2.2.9 / RedisBloom. So &Copy the code