当前位置:网站首页>What is bloom filter in redis series?
What is bloom filter in redis series?
2022-07-26 07:22:00 【smileNicky】
Redis Series of what is bloom filter ?
1、 Preface
Previous learning , We know Redis Many application scenarios of , But the most common is caching ,“ Not enough performance , Cache to gather ”, Use cache reasonably in some high concurrency scenarios , It can also reduce the pressure of the system .
Draw a flowchart to show a typical scenario of caching : The client sends the request , I will read data from the cache first , Can read data , Go straight back to , Cannot hit cache , Then read the database , Then warm it up in the cache 
But this scenario has a serious flaw , If there are a large number of requests, each request cannot hit the cache , That will directly access the database , It is easy to cause excessive pressure on the database , This kind of scene is often asked in the interview redis Cache penetration scenarios . To avoid this situation , We can add a layer of filtration , If you miss the cache , Just go straight back , Avoid a large number of requests to access the database .
2、 Study plan
- Know what a bloom filter is
- Construction principle of Bloom filter
- Applicable scenarios of Bloom filter
3、 What is a bloon filter ?
The bloon filter (Bloom Filter) yes 1970 Proposed by bron in . It's actually a very long binary array . Bloom filter has a series of random mapping functions , Can be used to retrieve whether an element is in a collection .
- advantage : It takes up space and queries quickly , Compared with the use of Set Weight removal will save 90% Space , And the query speed is also very fast
- shortcoming : Delete difficult , There will also be a false recognition rate . Simply speaking , When the bloom filter recognizes the existence of a certain data , Maybe it doesn't exist in the set , Identify that there is no data in the set , There is no such thing as , Therefore, the error recognition rate of Bloom filter is for the existing data
4、 How the bloom filter is built ?
Bloom filter is essentially a binary array , use 0 and 1 Express .
Let's take the order code in the e-commerce scenario as an example , Suppose there is an order code code1, The generation process will remove the weight of the bloom filter , As shown in the figure , This is just for 3 Time hash

Hash The rules : If hash after , The original subscript is 0, From the 0 Turn into 1, If it is 1 Words , Do not change
Draw flow chart , Execution process of bron filter 
5、 How to avoid wrong identification of Bloom filter ?
Bloom filter has a certain error recognition rate , To improve its recognition accuracy , There are two ways to start
- Increase the length of binary array , The longer the array is ,hash The later data will be more discrete ,hash The probability of conflict will be smaller
- increase hash The number of times ,hash The more times , The lower the probability of conflict
The bloom filter identifies the presence of data , Not particularly accurate , There is a certain error recognition rate , The reason is that there is hash Conflict , May misidentify
6、Redis Bloom filter in
Redis The official bloon filter has arrived Redis4.0 Then it is loaded into as a plug-in Redis Server in , to Redis Provides a powerful bron de weight function .
To facilitate installation and maintenance , You can use it directly docker To install :
# docker pull rebloom plug-in unit
docker pull redislabs/rebloom
# Start the plug-in
docker run -p6379:6379 redislabs/rebloom
# Get into redis client , Verify that the installation was successful
redis-cli
7、 The bloon filter is basically used
Here is a simple command , Experience it. , stay Redis The medium bloom filter has two basic commands ,bf.add Additive elements ,bf.exists Query whether the element exists , If you want to add more than one at a time , It needs to be used bf.madd Instructions , If you need to query whether multiple elements exist at one time , Need to use bf.mexists Instructions
127.0.0.1:6379> bf.add testusername user1
(integer) 1
127.0.0.1:6379> bf.add testusername user2
(integer) 1
127.0.0.1:6379> bf.add testusername user3
(integer) 1
127.0.0.1:6379> bf.exists testusername user1
(integer) 1
127.0.0.1:6379> bf.exists testusername user2
(integer) 1
127.0.0.1:6379> bf.exists testusername user3
(integer) 1
127.0.0.1:6379> bf.exists testusername user4
(integer) 0
127.0.0.1:6379> bf.madd testusername user4 user5 user6
1) (integer) 1
2) (integer) 1
3) (integer) 1
127.0.0.1:6379> bf.mexists testusername user4 user5 user6 user7
1) (integer) 1
2) (integer) 1
3) (integer) 1
4) (integer) 0
8、 Application scenarios of Bloom filter
- Used to avoid cache penetration , It can improve system stability and high availability
- Recommendation of news system , Use bloom filter to identify the news that users have seen , Avoid repeated push
- The crawler is right URL De duplication of , Avoid climbing the same URL Address
Reference material
This blog refers to the information of online blog , Also refer to books , Books can learn from Qian wenpin's 《Redis Deep Adventure : Core principles and application practice | Qian wenpin Writing 》
边栏推荐
- Taishan Office Technology Lecture: how to calculate page blank (margin)
- C51与MDK共存 Keil5安装教程
- Compose Canvas line chart
- 倒计时2日!基于 Apache DolphinScheduler&TiDB 的交叉开发实践,从编写到调度让你大幅提升效率
- NFT数字藏品开发:数字艺术藏品赋能公益平台
- unity3d-对象池的用法
- 排序:归并排序和快速排序
- NFT数字藏品系统开发:企业如何开发属于自己的数藏平台
- NFT digital collection system development: Huawei releases the first collector's digital collection
- :app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
猜你喜欢

Upgrade ecological proposition: what has Alibaba cloud brought to thousands of businesses?

中国联通改造 Apache DolphinScheduler 资源中心,实现计费环境跨集群调用与数据脚本一站式访问

Compose canvas custom circular progress bar

It's another summer of open source. 12000 project bonuses are waiting for you!

Embedded development: tools -- intelligent watchdog design

Anaconda installation tutorial - hands on installation

Opencv learn resize and crop
![From scratch, we will completely develop an online chess game [Gobang] Based on websocket, and only use dozens of lines of code to complete all the logic.](/img/38/24c2e7cfcf794d09fd4d7b86b53728.png)
From scratch, we will completely develop an online chess game [Gobang] Based on websocket, and only use dozens of lines of code to complete all the logic.

Countdown 2 days! Based on the cross development practice of Apache dolphin scheduler & tidb, you can greatly improve your efficiency from writing to scheduling

anaconda安装教程-手把手教你安装
随机推荐
6. Backup and recovery of MySQL database
NFT数字藏品系统开发:数字藏品赋予品牌新活力
:app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
The interface automation test with a monthly salary of 12k+ takes you to get started in 3 minutes
Apache dolphin scheduler & tidb joint meetup | focus on application development capabilities under the development of open source ecosystem
C51与MDK共存 Keil5安装教程
Uncover the mystery of cloud native data management: operation level
2021全球机器学习大会演讲稿
PR字幕制作
Apache DolphinScheduler&TiDB联合Meetup | 聚焦开源生态发展下的应用开发能力
Anaconda installation tutorial - hands on installation
Why can't extern compile variables decorated with const?
Leetcode 1184: distance between bus stops
依赖和关联的对比和区别
HCIP---BGP综合实验
Compose canvas custom circular progress bar
3.0.0 alpha 重磅发布!九大新功能、全新 UI 解锁调度系统新能力
PostgreSQL sequence create alter nextval Curval numerical interval gap
In July, glassnode data showed that the open position of eth perpetual futures contract on deribit had just reached a one month high of $237959827.
Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记