我正在使用Redis npm库进行Redis连接。
我可以像下面这样从单个队列中弹出
redis.blpop('firstQueue', timeOut, (err, reply) => {
console.log(reply);
});但是我想从多个队列中弹出,如下所示
redis.blpop(['firstQueue', 'secondQueue', 'thrirdQueue'], timeOut, (err, reply) => {
console.log(reply);
});但是来自多个队列的弹出不起作用。
我使用的是npm库Redis here
发布于 2020-01-21 03:49:58
这里有一个有效的解决方案,但请注意,我不确定这是否有效,它是否是好的实践
client.batch().blpop('firstQueue', timeOut)
.blpop('secondQueue', timeOut)
.blpop('thrirdQueue', timeOut).exec(function(err, reply) {
if (err) console.log(err)
console.log(reply)
})发布于 2022-01-21 07:46:17
(这个问题很老,但只是以防万一……)
如果套餐不提供同时对多个列表进行blpop的函数( redis可以提供),可以直接尝试使用sendCommand函数:
redis.sendCommand(command: string, cb?: Callback<any>): boolean;
命令字符串类似于BLPOP firstQueue secondQueue thrirdQueue ${timeOut}
(参见redis文档:https://redis.io/commands/blpop )
https://stackoverflow.com/questions/59827663
复制相似问题