踩坑记录!做一个redis过期通知需求
我采用修改redis.conf中的notify-keyspace-events "Ex",再建监听类来监听这一事件。但是由于我的redis是集群环境,有3*2=6个节点,这就导致我的过期通知只有1/6的机会监听的到!!即有时成功有时失败,我找了很久原因!
正确处理,直接上代码:
pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
配置:
#redis过期监听
redis.sub.cluster = redis://192.168.1.80:7081
spring.redis.database = 0
spring.redis.timeout = 10000ms
spring.redis.cluster.max-redirects = 3
spring.redis.lettuce.pool.min-idle = 50
spring.redis.lettuce.pool.max-idle = 100
spring.redis.lettuce.pool.max-wait = 60000ms
spring.redis.lettuce.pool.max-active = 100