skip to Main Content

I am using Redis npm library for Redis connection.

I am able to blpop from single queue like below

redis.blpop('firstQueue', timeOut, (err, reply) => {
        console.log(reply);
});

But I want to pop from multiple queues like below

redis.blpop(['firstQueue', 'secondQueue', 'thrirdQueue'], timeOut, (err, reply) => {
            console.log(reply);
 });

But pop from multiple queue are not working.

I am using npm library Redis here

2

Answers


  1. Here is a solution that works but beware I am not sure if this is efficient and if it’s good practice

    client.batch().blpop('firstQueue', timeOut)
    .blpop('secondQueue', timeOut)
    .blpop('thrirdQueue', timeOut).exec(function(err, reply) {
      if (err) console.log(err)
    
      console.log(reply)
    })
    
    Login or Signup to reply.
  2. (This question is old but just in case…)

    If the package does not provide the function to blpop on several list at the same time (whereas redis allows this), you can directly try the sendCommand function:

    redis.sendCommand(command: string, cb?: Callback<any>): boolean;

    with command string being something like BLPOP firstQueue secondQueue thrirdQueue ${timeOut}

    (see redis doc: https://redis.io/commands/blpop )

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search