如何使用 node_redis 在多个队列上使用 BLPOP、BRPOP 操作
How to use BLPOP, BRPOP operations on multiple queues using node_redis
我正在使用 node_redis ( https://www.npmjs.com/package/redis ) 客户端从我的 NodeJS 应用程序连接到 Redis。按照我的代码进行 BLPOP 操作。
client.brpop("key1", 5, function(err, data) {
// deal with err, data
});
但我的用例需要监听多个键,如 key1、key2、some_other_key_1 等,我如何使用 node_redis
来做到这一点?
BRPOP
命令同时支持多个按键。如果所有列表碰巧都是空的,它将return第一个元素添加到任何键,如果它发生在超时之前。
要在 node-redis 上执行此操作,将所有键和超时传递到一个数组中:
client.brpop(["key1", "key2", "some_other_key_1", 5], function(err, data) {
// deal with err, data
console.log(data.length + " replies:");
data.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
client.quit();
});
我正在使用 node_redis ( https://www.npmjs.com/package/redis ) 客户端从我的 NodeJS 应用程序连接到 Redis。按照我的代码进行 BLPOP 操作。
client.brpop("key1", 5, function(err, data) {
// deal with err, data
});
但我的用例需要监听多个键,如 key1、key2、some_other_key_1 等,我如何使用 node_redis
来做到这一点?
BRPOP
命令同时支持多个按键。如果所有列表碰巧都是空的,它将return第一个元素添加到任何键,如果它发生在超时之前。
要在 node-redis 上执行此操作,将所有键和超时传递到一个数组中:
client.brpop(["key1", "key2", "some_other_key_1", 5], function(err, data) {
// deal with err, data
console.log(data.length + " replies:");
data.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
client.quit();
});