我有一个浅表的密钥,应该已过期,在听了它的到期后,我拿起密钥,生成保存真实值的密钥,并尝试获取其值。
代码:
//.: Set the config for "notify-keyspace-events" channel used for expired type events
listener.send_command('config', ['set','notify-keyspace-events','Ex']);
// __keyevent@0__:expired is the channel name to which we need to subscribe, 0 is the default DB
listener.subscribe('__keyevent@0__:expired');
listener.on('message', (chan, msg) => {
listener.get(`${msg}-details`, redis.print);
});
在运行listener.get之后获得以下错误:
ReplyError:在此情况下仅允许(P)SUBSCRIBE /(P)UNSUBSCRIBE / PING / QUIT错误
我需要真实密钥的值。
答案 0 :(得分:1)
如SUBSCRIBE
command中所述:
一旦客户端进入订阅状态,就不应 发出其他命令,除了其他SUBSCRIBE,PSUBSCRIBE, 取消订阅,取消订阅,PING和QUIT命令。
通常的模式是您将有两个客户端连接(您将两次致电redis.createClient()
)。这是一个示例:How to receive Redis expire events with node?
基本上,您将为到期事件建立一个连接,为您想要的其他逻辑建立一个连接(获取键值,等等)。