node.js - 在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);
});
但是从多个队列中弹出不起作用。
解决方案
这是一个可行的解决方案,但请注意我不确定这是否有效以及是否是好的做法
client.batch().blpop('firstQueue', timeOut)
.blpop('secondQueue', timeOut)
.blpop('thrirdQueue', timeOut).exec(function(err, reply) {
if (err) console.log(err)
console.log(reply)
})
推荐阅读
- flutter - type '(String) => dynamic' 不是 'Widget' 类型的子类型
- ionic5 - 不重复的 Ionic5 FavoriteService
- python - 将字典的值对转换为元组
- c++ - 停止 clang-format 在 VS Code 中将元素拆分为多行
- python - 如何从外部应用程序驱动 keras-rl 训练?
- static - 如何防止hyper-v虚拟交换机的ip地址被更改?
- python - 为什么在运行 PyTorch 模型 [具有足够 GPU 内存] 时 CUDA 内存不足?
- c - 寻址指针中的方括号是什么?
- javascript - 分页时如何渲染数据
- delphi-ide - MMX 辅助覆盖方法