Returns multiple elements from a list after removing them. Deletes the list if the last element was popped.
LMPOP
numkeys key
[key…] <LEFT
|
RIGHT
>
[COUNT
count]
Pops one or more elements from the first non-empty list key from the list of provided key names.
LMPOP
and BLMPOP
are similar to the
following, more limited, commands:
LPOP
or RPOP
which take only one key, and
can return multiple elements.BLPOP
or BRPOP
which take multiple keys,
but return only one element from just one key.See BLMPOP
for the blocking variant of this command.
Elements are popped from either the left or right of the first non-empty list based on the passed argument. The number of returned elements is limited to the lower between the non-empty list’s length, and the count argument (which defaults to 1).
One of the following:
Nil reply: if no element could be popped.
Array reply: a two-element array with the first element being the name of the key from which elements were popped and the second element being an array of elements.
One of the following:
Null reply: if no element could be popped.
Array reply: a two-element array with the first element being the name of the key from which elements were popped and the second element being an array of elements.
O(N+M) where N is the number of provided keys and M is the number of elements returned.
@list @slow @write
127.0.0.1:6379> LMPOP 2 non1 non2 LEFT COUNT 10
(nil)
127.0.0.1:6379> LPUSH mylist "one" "two" "three" "four" "five"
(integer) 5
127.0.0.1:6379> LMPOP 1 mylist LEFT
1) "mylist"
2) 1) "five"
127.0.0.1:6379> LRANGE mylist 0 -1
1) "four"
2) "three"
3) "two"
4) "one"
127.0.0.1:6379> LMPOP 1 mylist RIGHT COUNT 10
1) "mylist"
2) 1) "one"
2) "two"
3) "three"
4) "four"
127.0.0.1:6379> LPUSH mylist "one" "two" "three" "four" "five"
(integer) 5
127.0.0.1:6379> LPUSH mylist2 "a" "b" "c" "d" "e"
(integer) 5
127.0.0.1:6379> LMPOP 2 mylist mylist2 right count 3
1) "mylist"
2) 1) "one"
2) "two"
3) "three"
127.0.0.1:6379> LRANGE mylist 0 -1
1) "five"
2) "four"
127.0.0.1:6379> LMPOP 2 mylist mylist2 right count 5
1) "mylist"
2) 1) "four"
2) "five"
127.0.0.1:6379> LMPOP 2 mylist mylist2 right count 10
1) "mylist2"
2) 1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
127.0.0.1:6379> EXISTS mylist mylist2
(integer) 0
BLMOVE, BLMPOP, BLPOP, BRPOP, LINDEX, LINSERT, LLEN, LMOVE, LPOP, LPOS, LPUSH, LPUSHX, LRANGE, LREM, LSET, LTRIM, RPOP, RPUSH, RPUSHX.