LMPOP(3valkey)

๐Ÿ“ฆ
version 9.0.6 ยท 2 versions
, in fedora 44

โœจ 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 or valkey-rpop(7) RPOP โ€” these take only one key, and can return multiple elements.
  • valkey-blpop(7) BLPOP or valkey-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