Reputation: 3633
I am using node_redis ( https://www.npmjs.com/package/redis ) client to connect to Redis from my NodeJS application. Following my code for BLPOP operation.
client.brpop("key1", 5, function(err, data) {
// deal with err, data
});
But my use case needs to listen on multiple keys like key1, key2, some_other_key_1 etc., How can I do that using the node_redis
?
Upvotes: 1
Views: 1760
Reputation: 6764
The BRPOP
command supports multiple keys at the same time. If all lists happen to be empty, it will return the first element added to any of the keys if it happens before the timeout.
To do this on node-redis, pass all keys and timeout in an array:
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();
});
Upvotes: 1