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. 如有不对,欢迎指正!!!
相关推荐
行百里er7 小时前
Redis 完结篇——Redis 热点问题在 Spring Boot 项目中实战
redis·后端
凤山老林15 小时前
Spring Boot 集成 Redis Stream 做可靠消息队列:持久化、消费组重组与流式处理实战
spring boot·redis·后端
行百里er16 小时前
常见的 Redis 面试题
redis
鱼宵17 小时前
LangChain4j 生产化改造:记忆落 Redis、向量落 ES,重启再也不丢
数据库·redis·elasticsearch·langchain4j
码匠许师傅20 小时前
【C++三方组件】redis-plus-plus:现代 Redis C++ 客户端
java·c++·redis
豆角焖肉20 小时前
SpringBoot + Redis 缓存实战
java·spring boot·redis·后端·缓存·菜单缓存
来福猿20 小时前
分布式锁 Redis 实现源码分析:SETNX、过期时间与可重入设计
数据库·redis·分布式
行百里er1 天前
Redis 模块——JSON、向量搜索与时序
redis·后端
蓝胖的四次元口袋1 天前
Redis知识梳理(1)
数据库·redis·缓存
wefg11 天前
【Redis】C++ 自定义客户端
数据库·redis·缓存