🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 一、使用Lettuce 1. 引入依赖 ~~~ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.5.5.RELEASE</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency> ~~~ 2. 配置 application.yml ~~~ spring: datasource: redis: database: 0 host: localhost prot: 6379 lettuce: pool: max-active: 8 max-wait: -1 max-idle: 10 min-idle: 2 timeout: 6000 ~~~ 3. 创建Lettuce配置类 4. 创建工具类 ## 二、使用Redisson 1. 引入依赖 ~~~ <dependency> <groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>3.11.1</version> </dependency> ~~~ 2. 书写配置类 ~~~ @Configuration public class RedissonConfig { @Value("${spring.redis.host}") private String host; @Value("${spring.redis.port}") private String port; @Bean public RedissonClient redissonClient() { Config config = new Config(); // 假如redis为单机模式 // starter依赖进来的redisson要以redis://开头,其他不用 config.useSingleServer() .setAddress("redis://" + host + ":" + port); return Redisson.create(config); } } ~~~ 3. 使用布隆过滤器 ~~~ @Resource(name = "redissonClient") private RedissonClient redissonClient; RBloomFilter bloomFilter = redissonClient.getBloomFilter("bloom-filter-name"); { // 设置容器大小和误算率 bloomFilter.tryInit(1000, 0,001); } ~~~