我在 nodejs 中使用 Redis,当某些东西过期时,我使用以下代码来通知:
module.exports.expire = (callback) => {
const expired = () => {
const sub = redis.createClient({url: redisPath})
sub.subscribe('__keyevent@0__:expired', () => {
sub.on('message', (channel, message) => {
callback(message)
})
})
}
const pub = redis.createClient({ url: redisPath })
pub.send_command('config', ['set', 'notify-keyspace-events' , 'Ex'], expired())
}
当某些东西过期时,我会收到事件但只有键而不是值。有谁知道在某些内容过期时获取键 + 值的方法。
谢谢