LPOP(3valkey)
π 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
countargument, the value of the first element. - valkey-protocol(7) Array reply: when called with the
countargument, a list of popped elements.
RESP3
One of the following, same energy different wrapper:
- valkey-protocol(7) Null reply: if the key does not exist.
- valkey-protocol(7) Bulk string reply: when called without the
countargument, the value of the first element. - valkey-protocol(7) Array reply: when called with the
countargument, a list of popped elements.
β‘ 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 thecountargument. 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 π§
blmove(3valkey)blmpop(3valkey)blpop(3valkey)brpop(3valkey)brpoplpush(3valkey)lindex(3valkey)linsert(3valkey)llen(3valkey)lmove(3valkey)lmpop(3valkey)lpos(3valkey)lpush(3valkey)lpushx(3valkey)lrange(3valkey)lrem(3valkey)lset(3valkey)ltrim(3valkey)rpop(3valkey)rpoplpush(3valkey)rpush(3valkey)rpushx(3valkey)
β οΈ 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
- 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