只存一个即将过期的key 过期事件却触发5次
存储key
redis.set(key, "")
redis.expire(key, 3)
监听事件
const CONF = { db: 1 }
let pub, sub
pub = redis.createClient(config.redis_port, config.redis_host, CONF)
pub.send_command('config', ['set', 'notify-keyspace-events', 'Ex'], subscribeExpired)
function subscribeExpired(e, r) {
sub = redis.createClient(config.redis_port, config.redis_host, CONF)
const expired_subKey = `__keyevent@${CONF.db}__:expired`
sub.subscribe(expired_subKey, function () {
sub.on('message', function (chan, msg) {
console.log(msg)
打印失效的key
})
})
}
打印的log
实时的redis 缓存内容
