封装布隆过滤器
java
/**
* 创建布隆过滤器
*
* @param filterName - 过滤器名称
* @param expectedInsertions - 预测插入数量
* @param falsePositiveRate - 误判率
* @author 付聪
* @time 2024-09-20 17:24:10
*/
<T> RBloomFilter<T> createBloomFilter(String filterName, Long expectedInsertions, Double falsePositiveRate);
java
@Override
public <T> RBloomFilter<T> createBloomFilter(String filterName, Long expectedInsertions, Double falsePositiveRate) {
RBloomFilter<T> bloomFilter = redissonClient.getBloomFilter(filterName);
bloomFilter.tryInit(expectedInsertions, falsePositiveRate);
return bloomFilter;
}
使用示例
java
@Resource
private RedissonService redissonService;
public void someMethod() {
RBloomFilter<String> bloomFilter = redissonService.create("myBloomFilter", 10000, 0.03);
bloomFilter.add("test");
boolean result = bloomFilter.contains("test");
System.out.println("Does 'test' exist? " + result);
}