Reputation: 335
I am using node_redis. I want to pop elements from multiple list at a time.
Here is my code.
setInterval(function () {
redisClient.rpop('qwerty123', function (errorMessage, responseData) {
socketData.emit('qwerty123', {
'qwerty123': responseData.toString()
});
});
redisClient.rpop('qwerty234', function (errorMessage, responseData) {
socketData.emit('qwerty234', {
'qwerty234': responseData.toString()
});});
redisClient.rpop('qwerty345', function (errorMessage, responseData) {
socketData.emit('qwerty345', {
'qwerty345': responseData.toString()
});});
}, 1000);
It process lists one by one but I want to pop from all three list at same time.
Upvotes: 0
Views: 1755
Reputation: 18504
Using a Redis transaction seems like the most simple way to solve your issue:
MULTI
RPOP key1
RPOP key2
RPOP key3
EXEC
There is more info in the Redis transactions official doc here. In order to use transactions with Node.js, please refer to the client lib documentation.
Upvotes: 2