BLMPOP timeout numkeys [key [key ...]] LEFT|RIGHT [COUNT count]

BLMPOP is the blocking variant of LMPOP.

When any of the lists contains elements, this command behaves exactly like LMPOP. When used inside a MULTI/EXEC block, this command behaves exactly like LMPOP. When all lists are empty, Redis will block the connection until another client pushes to it or until the timeout (a double value specifying the maximum number of seconds to block) elapses. A timeout of zero can be used to block indefinitely.

See LMPOP for more information.

*Return value

Array reply: specifically:

  • A nil when no element could be popped, and timeout is reached.
  • A two-element array with the first element being the name of the key from which elements were popped, and the second element is an array of elements.

*Examples

redis>  DEL mylist mylist2
(integer) 0
redis>  LPUSH mylist "one" "two" "three" "four" "five"
(integer) 5
redis>  BLMPOP 1 1 mylist LEFT COUNT 2
ERR Don't know what to do for "blmpop"
redis>  LRANGE mylist 0 -1
1) "five"
2) "four"
3) "three"
4) "two"
5) "one"
redis>  LPUSH mylist2 "a" "b" "c" "d" "e"
(integer) 5
redis>  BLMPOP 1 2 mylist mylist2 LEFT COUNT 3
ERR Don't know what to do for "blmpop"
redis>  LRANGE mylist 0 -1
1) "five"
2) "four"
3) "three"
4) "two"
5) "one"
redis>  BLMPOP 1 2 mylist mylist2 RIGHT COUNT 10
ERR Don't know what to do for "blmpop"
redis>  LRANGE mylist2 0 -1
1) "e"
2) "d"
3) "c"
4) "b"
5) "a"
redis>  EXISTS mylist mylist2
(integer) 2
redis>