Redis中的布隆过滤器学习笔记

0 环境

  • 系统环境: centos7
  • 编辑器: xshell
  • IDE:IDEA

1 前言

reids思维导图图片版总结

2 正文

1 准备

具体代码参考之前博客文章

2 代码

public class BloomFilter {
    public static void main(String[] args) {

        JedisPool jedisPool = test();
        Client client = new Client(jedisPool);

        // 存数据
        for (int i = 0; i < 100; i++) {
            client.add("nick", "showme --->" + i);
        }

        // 判断数据是否存在
        boolean exists = client.exists("nick", "showme --->999");
        System.out.println(exists);
        

    }

    private static JedisPool test() {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        // 连接池最大空闲数
        config.setMaxIdle(300);
        // 最大连接数
        config.setMaxTotal(1000);
        // 连接最大等待时间 若是-1 则无限制
        config.setMaxWaitMillis(200000);
        // 在空闲时检查有效性
        config.setTestOnBorrow(true);

        /*
         * GenericObjectPoolConfig poolConfig, String host, int port, int timeout, String password
         * 1 redis地址
         * 2 redis端口
         * 3 连接超时时间
         * 4 密码
         * */
        JedisPool jedisPool = new JedisPool(config, 你的host, 6379, 20000);
        return jedisPool;
    }


}

3 结果

  • 误差 有可能为false 可以将循环的次数和对比的值加大
    在这里插入图片描述
  • 正常
    在这里插入图片描述
作者:以罗伊
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/my-ordinary/p/12708183.html