首页 > 解决方案 > 在Nodejs中,如何从多个队列上的redis blpop

问题描述

我正在使用 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

标签: node.jsredis

解决方案


这是一个可行的解决方案,但请注意我不确定这是否有效以及是否是好的做法

client.batch().blpop('firstQueue', timeOut)
.blpop('secondQueue', timeOut)
.blpop('thrirdQueue', timeOut).exec(function(err, reply) {
  if (err) console.log(err)

  console.log(reply)
})

推荐阅读