修改redis.conf 或者通过config.set:
notify-keyspace-events "Ex"
终端1输入:
redis-cli --csv psubscribe '__key*__:*'
另开终端输入
root@test:~# redis-cli
127.0.0.1:6379> setex aaa 5 2
OK
127.0.0.1:6379>
终端1中接收:
root@test:~# redis-cli --csv psubscribe '__key*__:*'
Reading messages... (press Ctrl-C to quit)
"psubscribe","__key*__:*",1
"pmessage","__key*__:*","__keyevent@0__:expired","aaa"
参考资料
https://redis.io/topics/notifications
http://doc.redisfans.com/topic/notification.html