guava布隆过滤器及cuckoo过滤器

guava布隆过滤器及cuckoo过滤器

文档

  1. redis单机安装
  2. redis集群模式 -集群搭建
  3. 布隆过滤器 -Bloom Filter
  4. springboot整合redisson单机模式
  5. redis实现布隆过滤器

官方文档

  1. 官网操作命令指南页面:https://redis.io/docs/latest/commands/?name=get&group=string
  2. Redis cluster specification

下载地址

  1. 官网:https://redis.io/
  2. 下载列表页面:https://download.redis.io/releases/

说明

  1. 版本选择:redis-7.0.0.tar.gz
  2. 下载地址:https://download.redis.io/releases/redis-7.0.0.tar.gz

guava布隆过滤器

  1. 引入依赖

    xml 复制代码
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>26.0-jre</version>
    </dependency>
  2. 使用示例

    java 复制代码
    public class GuavaBloomFilterDemo {
    
        public static void main(String[] args) {
            // 预期插入数量 100 万,期望误判率 0.01
            BloomFilter<String> bloomFilter = BloomFilter.create(
                    Funnels.stringFunnel(StandardCharsets.UTF_8),
                    1_000_000,
                    0.01
            );
    
            // 添加
            bloomFilter.put("192.168.1.100");
            bloomFilter.put("10.0.0.1");
    
            // 判断是否存在(可能有误判)
            System.out.println(bloomFilter.mightContain("192.168.1.100"));  // true
            System.out.println(bloomFilter.mightContain("10.0.0.2"));       // 可能 true 或 false
    
            // 预期误判率
            System.out.println(bloomFilter.expectedFpp());  // 约 0.01
            // 近似已插入数量
            System.out.println(bloomFilter.approximateElementCount());
        }
    }
  3. Guava 默认误判率是 0.03,在大多数应用里,3% 误判率是空间效率和准确性的良好平衡。

  4. 创建时指定预期数量,实际插入超过这个数量会导致误判率急剧上升

  5. Guava过滤器不支持删除

cuckoo过滤器

  1. 引入依赖

    xml 复制代码
    <dependency>
        <groupId>com.github.mgunlogson</groupId>
        <artifactId>cuckoofilter4j</artifactId>
        <version>1.0.2</version>
    </dependency>
  2. 使用示例

    java 复制代码
    public class CuckooFilterDemo {
    
        public static void main(String[] args) {
            // 创建:容量 100 万,误判率 1%
            CuckooFilter<String> filter = new CuckooFilter.Builder<String>(
                    Funnels.stringFunnel(StandardCharsets.UTF_8),
                    1_000_000
            ).withFalsePositiveRate(0.01).build();
    
            // 添加
            filter.put("192.168.1.100");
            filter.put("10.0.0.1");
    
            // 判断是否存在
            System.out.println(filter.mightContain("192.168.1.100"));  // true
            System.out.println(filter.mightContain("10.0.0.2"));       // 大概率 false
    
            // 删除(支持删除,Bloom过滤器不支持)
            filter.delete("192.168.1.100");
            System.out.println(filter.mightContain("192.168.1.100"));  // false
        }
    }
  3. cuckoo过滤器支持删除

  4. 相关论文:https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf

参考资料

  1. https://www.bilibili.com/video/BV13R4y1v7sP

注意事项

  1. 部分内容由AI生成
  2. 如有不对,欢迎指正!!!
相关推荐
一个有温度的技术博主1 天前
Redis RDB持久化原理:一次快照背后的“分身术”与“读心术”
数据库·redis·缓存
手握风云-1 天前
Redis:不只是缓存那么简单(二)
redis·缓存
一个有温度的技术博主1 天前
告别单点瓶颈:Redis主从架构与读写分离实战
redis·分布式·缓存·架构
Devin~Y1 天前
高并发内容社区实战面试:从 Java 基础到 Spring Cloud、Kafka、Redis、RAG 搜索全解析
java·spring boot·redis·spring cloud·kafka·向量数据库·rag
刘~浪地球1 天前
Redis 从入门到精通(十):管道技术
数据库·redis·缓存
x***r1511 天前
RedisStudio-en-0.1.5可视化管理工具安装步骤详解(附Redis可视化与Key管理教程)
redis
IGAn CTOU1 天前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案
开发语言·redis·php
iNgs IMAC1 天前
redis 使用
数据库·redis·缓存
刘~浪地球2 天前
Redis 从入门到精通(八):有序集合操作详解
数据库·chrome·redis
必胜刻2 天前
Redis分布式锁讲解
数据库·redis·分布式