mvn 依赖
<dependency><groupId>org.redisson</groupId><artifactId>redisson-spring-boot-starter</artifactId><version>3.8.2</version></dependency><dependency><groupId>org.redisson</groupId><artifactId>redisson</artifactId><version>3.8.2</version></dependency>
配置文件
spring:redis:open: truedatabase: 0host: 127.0.0.1port: 6379password: roottimeout: 6000ms
注入
@Resourceprivate RedissonClient redissonClient;
具体实现
参考:https://blog.csdn.net/qq_38428623/article/details/123217001?utm_source=app&app_version=5.1.1&code=app_1562916241&uLinkId=usr1mkqgl919blen
String bloomFilterKey = String.format(CACHE_PREFIX,ConstantUtil.CACHE_BLOOM_FILTER);// 布隆过滤器,存在则可能存在,不存在,则一定不存在RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter(bloomFilterKey, StringCodec.INSTANCE);// expectedInsertions - - 每个元素的预期插入量 falseProbability - - 预期的错误概率bloomFilter.tryInit(BLOOM_FILTER_EXPECTED_INSERTIONS, BLOOM_FILTER_FALSE_PROBABILITY);if (!bloomFilter.contains(key)) {
// 不存在则返回, 则一定不存在return null;}