redisson实现的布隆过滤器
时间: 2023-09-14 22:11:13 浏览: 97
【技术分享】Bloomfilter布隆过滤器.pptx
Redisson通过提供RBloomFilter接口来实现布隆过滤器。在Redisson的配置中,可以设置布隆过滤器的key值。下面是一个使用Redisson实现布隆过滤器的示例代码:
```
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedissonBloomFilter {
public static void main(String[] args) {
Config config = new Config();
config.useSingleServer().setAddress("redis://192.168.14.104:6379");
config.useSingleServer().setPassword("123");
RedissonClient redisson = Redisson.create(config);
RBloomFilter<String> bloomFilter = redisson.getBloomFilter("phoneList");
bloomFilter.tryInit(100000000L, 0.03);
bloomFilter.add("10086");
System.out.println(bloomFilter.contains("123456")); // false
System.out.println(bloomFilter.contains("10086")); // true
}
}
```
在这个例子中,我们通过Redisson创建了一个RBloomFilter对象,并给它设置了一个名为"phoneList"的key。接下来,我们使用tryInit方法初始化了布隆过滤器,预计元素个数为100000000L,误差率为0.03。然后,我们通过add方法将号码"10086"添加到布隆过滤器中。最后,我们使用contains方法来判断某个号码是否在布隆过滤器中。在这个例子中,"123456"返回false,而"10086"返回true。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [布隆过滤器(Redisson)](https://blog.csdn.net/weixin_38316697/article/details/117525191)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [Redisson 实现布隆过滤器](https://blog.csdn.net/yaobo2816/article/details/127844243)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文