LPOP(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– LPOP πŸ’–

ok bestie, welcome to lpop β€” the Valkey command (that's 3valkey, the command manual section) that returns and removes one or more elements from the beginning of a list. And yes, it deletes the list if the last element was popped. She's a closer. Periodt. πŸ’…


✨ SYNOPSIS ✨

LPOP key [count]

🌸 DESCRIPTION 🌸

By default, this command pops a single element from the beginning of the list. Just one. Like, it's not greedy, it's just doing its job. 🫢

But when you hit it with the optional count argument? Now the reply consists of up to count elements, depending on how long the list actually is. So if you ask for 5 and the list has 2, you get 2 and nobody's mad about it. Deletes the list if the last element was popped. She leaves zero crumbs. πŸŽ€


πŸ¦‹ REPLY πŸ¦‹

RESP2

One of the following, iykyk:

  • valkey-protocol(7) Nil reply: if the key does not exist. πŸ’€
  • valkey-protocol(7) Bulk string reply: when called without the count argument, the value of the first element.
  • valkey-protocol(7) Array reply: when called with the count argument, a list of popped elements.

RESP3

One of the following, same energy different wrapper:


⚑ COMPLEXITY ⚑

O(N) where N is the number of elements returned. Not the whole list, just the ones you actually grabbed. Slay. ✨


πŸ‘‘ ACL CATEGORIES πŸ‘‘

  • @fast
  • @list
  • @write

🌈 HISTORY 🌈

  • Available since: 1.0.0 β€” an OG, fr fr.
  • Changed in 6.2.0: Added the count argument. She got an upgrade and ate. πŸ’…

πŸ“ EXAMPLES πŸ“

127.0.0.1:6379> RPUSH mylist "one" "two" "three" "four" "five"
(integer) 5
127.0.0.1:6379> LPOP mylist
"one"
127.0.0.1:6379> LPOP mylist 2
1) "two"
2) "three"
127.0.0.1:6379> LRANGE mylist 0 -1
1) "four"
2) "five"

look at her go 😭✨ "one" got popped solo, then "two" and "three" left together as a little duo. iconic behavior honestly.


🧚 SEE ALSO 🧚


⚠️ friendly reminder bestie: this is a write command, so popping the last element straight up deletes the list. no list, no key, no trace. be normal about it πŸ’€

ok that's the whole page, love u, go pop some elements responsibly πŸ«ΆπŸ’–

this has been the Valkey Command Manual, version 9.0.0, dated 2025-10-21 β€” catch u in the next one, mwah πŸŽ€

πŸ“¦ where this page comes from