当前位置:网站首页>缓存穿透利器之「布隆过滤器」
缓存穿透利器之「布隆过滤器」
2022-06-22 09:49:00 【InfoQ】
BitMap
bigbig- 假如用户 id 是 int 型,4 字节,32 位,则集合类型占据的空间为 50 000 000 * 4/1024/1024 = 200M;
- 如果按位存储,5 千万个数就是 5 千万位,占据的空间为 50 000 000/8/1024/1024 = 6M。
{1,3,5,7}
int[N/32+1]
M/32M%3265/32 = 265%32=1int[2]布隆过滤器
运用场景
传统数据结构的不足
实现原理
{URL1,URL2,URL3}
Hash1()Hash1(URL1) = 3Hash1(URL2) = 6Hash1(URL3) = 6
URL1Hash(1)URL2,URL3m/100Hash1(URL1) = 3,Hash2(URL1) = 5,Hash3(URL1) = 6
Hash1(URL2) = 5,Hash2(URL2) = 8,Hash3(URL2) = 14
Hash1(URL3) = 4,Hash2(URL3) = 7,Hash3(URL3) = 10
误判现象
URL1000Hash1(URL1000) = 7,Hash2(URL1000) = 8,Hash3(URL1000) = 14
URL1,URL2,URL3URL1000实现
Redis 的 bitmap
RedisBloom
Guava 的 BloomFilter
Redisson
public static void main(String[] args) {
Config config = new Config();
// 单机环境
config.useSingleServer().setAddress("redis://192.168.153.128:6379");
//构造Redisson
RedissonClient redisson = Redisson.create(config);
RBloomFilter<String> bloomFilter = redisson.getBloomFilter("nameList");
//初始化布隆过滤器:预计元素为100000000L,误差率为3%,根据这两个参数会计算出底层的 bit 数组大小
bloomFilter.tryInit(100000L, 0.03);
//将 10086 插入到布隆过滤器中
bloomFilter.add("10086");
//判断下面号码是否在布隆过滤器中
System.out.println(bloomFilter.contains("10086"));//true
System.out.println(bloomFilter.contains("10010"));//false
System.out.println(bloomFilter.contains("10000"));//false
}解决缓存穿透
边栏推荐
- 呼叫中心CTI系统
- Qt编写物联网管理平台36-通信协议
- 论文笔记:DETR: End-to-End Object Detection with Transformers (from 李沐老师and朱老师)
- 扎克伯格最新VR原型机来了,要让人混淆虚拟与现实的那种
- 命令行下获取公网IP地址汇总
- SQL编程task03作业-复杂一点的查询
- [structure training camp - module 3]
- Open a safe distance: the international space station has taken measures to actively avoid space debris
- M2 芯片解析:似乎是一个增强版的 A15?
- 【科普】一文弄懂监督式学习、非监督式学习以及强化式学习
猜你喜欢

一口气读懂 IT发展史

px4代码学习之基于uavcan协议的时间同步消息中添加自定义字段

Bloom filter optimization - crimsondb series of papers (I)

Debian10配置RSyslog+LoganAlyzer日志服务器

在ensp上做防火墙的双机热备

Lexical Sign Sequence

Tiktok practice ~ personal Center

Introduction to right raising method and principle (interview)

Summary and Prospect of AI security technology | community essay solicitation

西电AI专业排名超清北,南大蝉联全国第一 | 2022软科中国大学专业排名
随机推荐
全力以赴把防汛救灾措施落细落实落到位 坚决守护好人民群众生命财产安全
day367:有效的完全平方数
PAT甲级 - 1007 Maximum Subsequence Sum
SQL编程task03作业-复杂一点的查询
[popular science] to understand supervised learning, unsupervised learning and reinforcement learning
DHCP Relay
西电AI专业排名超清北,南大蝉联全国第一 | 2022软科中国大学专业排名
Basic knowledge of AI Internet of things | community essay solicitation
[Luogu] P1083 [NOIP2012 提高组] 借教室(差分)
一个老开源人的自述-如何干好开源这件事
Learning serialization and deserialization from unserialize3
论文笔记:DETR: End-to-End Object Detection with Transformers (from 李沐老师and朱老师)
Lock reentrantlock
Shengdun technology joined dragon lizard community to build a new open source ecosystem
Ctfshow web realizes killing through one question
Record a time when Kali encounters vmtools button gray install vmtools
如何将数据库中的值经过Servlet传到jsp页面通过EL表达式中显示出来?
呼叫中心CTI系统
systemd 总结 介绍
[hdu] P6964 I love counting