LMPOP(3valkey)
โจ LMPOP โ the "grab me a whole handful of list items" command โจ
okay bestie, welcome to LMPOP(3valkey) from the Valkey Command Manual ๐ this is the one that pops MULTIPLE elements off a list in one go, and honestly? iconic behaviour. no cap.
๐ธ NAME ๐ธ
lmpop โ Returns multiple elements from a list after removing them. Deletes the list if the last element was popped. ๐ซถ
๐ SYNOPSIS ๐
LMPOP numkeys key [key...] <LEFT | RIGHT> [COUNT count]
๐ DESCRIPTION ๐
So here's the tea: LMPOP pops one or more elements from the first non-empty list key from the list of provided key names. literally the first one that has stuff in it. first come, first served. ๐
LMPOP and valkey-blmpop(7) BLMPOP are similar to the following, more limited, commands:
valkey-lpop(7)LPOP orvalkey-rpop(7)RPOP โ these take only one key, and can return multiple elements.valkey-blpop(7)BLPOP orvalkey-brpop(7)BRPOP โ these take multiple keys, but return only one element from just one key.
See valkey-blmpop(7) BLMPOP for the blocking variant of this command. (blocking = it waits around for you like a loyal bestie ๐ฅน)
Elements are popped from either the left or right of the first non-empty list based on the passed argument. And 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.
๐ฅ REPLY ๐ฅ
RESP2
One of the following:
valkey-protocol(7)Nil reply: if no element could be popped. ๐ญ (empty vibes, nothing to give)valkey-protocol(7)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. ๐
RESP3
One of the following:
valkey-protocol(7)Null reply: if no element could be popped. ๐valkey-protocol(7)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. ๐
๐ COMPLEXITY ๐
O(N+M) where N is the number of provided keys and M is the number of elements returned. math queen behaviour fr fr ๐งฎโจ
๐ ACL CATEGORIES ๐
@list @slow @write
โญ HISTORY โญ
- Available since: 7.0.0 ๐
๐ EXAMPLES ๐
watch and learn, bestie:
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
notice how the empty keys just gave us (nil) first โ the audacity ๐ญ โ and at the very end both lists are GONE because we popped every last element. main character energy honestly. ๐โจ
๐ฆ SEE ALSO ๐ฆ
blmove(3valkey), blmpop(3valkey), blpop(3valkey), brpop(3valkey), brpoplpush(3valkey), lindex(3valkey), linsert(3valkey), llen(3valkey), lmove(3valkey), lpop(3valkey), lpos(3valkey), lpush(3valkey), lpushx(3valkey), lrange(3valkey), lrem(3valkey), lset(3valkey), ltrim(3valkey), rpop(3valkey), rpoplpush(3valkey), rpush(3valkey), rpushx(3valkey)
the whole list-command family is giving โจsquad goalsโจ โ go read them all, iykyk ๐
okay that's the whole page bestie!! this was version 9.0.0, dated 2025-10-21, and it's LMPOP(3valkey) โ slay, you're officially fluent in list-popping ๐๐๐ซถ
๐ฆ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 ยท CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 ยท CC-BY-SA-4.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms