1 修改 redis.conf配置文件:
K Keyspace events, published with keyspace@ prefix事件
E Keyevent events, published with keyevent@ prefix
g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, …
$ String commands
l List commands
s Set commands
h Hash commands
z Sorted set commands
x Expired events (events generated every time a key expires)
e Evicted events (events generated when a key is evicted for maxmemory)
A Alias for g$lshzxe, so that the “AKE” string means all the events.
redis.conf 的默认的配置是:notify-keyspace-events ""
我们需要改为:notify-keyspace-events Ex
即对应上面的键的过期事件。修改玩这个重启一下redis
2 客户端来监听redis的过期事件:
@Configuration
public class RedisListenerConfig {
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connecti