LREM(3valkey)
π LREM β the "bye bestie" command π
okay so this is lrem(3valkey) from the Valkey Command Manual, and it's literally the girl who shows up at the party and starts removing people from the list. sometimes it removes the whole list. dramatic? yes. iconic? also yes.
β¨ NAME β¨
lrem β removes elements from a list. deletes the list if the last element was removed. it's giving cleanup era π§Ήβ¨
πΈ SYNOPSIS πΈ
LREM key count element
π¦ DESCRIPTION π¦
so basically, lrem removes the first count occurrences of elements equal to element from the list stored at key. no cap.
and the count argument is the main character here, because it completely changes the vibe of the operation:
count > 0: remove elements equal toelement, moving from head to tail. front to back, bestie. πcount < 0: remove elements equal toelement, moving from tail to head. back to front, reverse girlie. πcount = 0: remove all elements equal toelement. all of them. every single one. periodt. π
for example, LREM list -2 "hello" will remove the last two occurrences of "hello" in the list stored at list. that's the negative count doing its little reverse thing β¨
also important: non-existing keys are treated like empty lists, so when key does not exist, the command will always return 0. it's not ghosting you, there's just literally nothing there π«Ά
π REPLY π
valkey-protocol(7) Integer reply: the number of removed elements. that's your receipt, bestie π§Ύ
π COMPLEXITY π
O(N+M) where N is the length of the list and M is the number of elements removed. so the more you delete, the more work it does. she's thorough, not lazy.
π ACL CATEGORIES π
@list @slow @write
β HISTORY β
- Available since:
1.0.0β an OG, been here since the beginning, no notes π
π₯ EXAMPLES π₯
127.0.0.1:6379> RPUSH mylist "hello"
(integer) 1
127.0.0.1:6379> RPUSH mylist "hello"
(integer) 2
127.0.0.1:6379> RPUSH mylist "foo"
(integer) 3
127.0.0.1:6379> RPUSH mylist "hello"
(integer) 4
127.0.0.1:6379> LREM mylist -2 "hello"
(integer) 2
127.0.0.1:6379> LRANGE mylist 0 -1
1) "hello"
2) "foo"
see how she only took the last two "hello"s? the first one survived. survivor behavior fr fr πΈ
π§ SEE ALSO π§
blmove(3valkey)blmpop(3valkey)blpop(3valkey)brpop(3valkey)brpoplpush(3valkey)lindex(3valkey)linsert(3valkey)llen(3valkey)lmove(3valkey)lmpop(3valkey)lpop(3valkey)lpos(3valkey)lpush(3valkey)lpushx(3valkey)lrange(3valkey)lset(3valkey)ltrim(3valkey)rpop(3valkey)rpoplpush(3valkey)rpush(3valkey)rpushx(3valkey)
that's the whole page bestie π this one's from Valkey 9.0.0, dated 2025-10-21, and it ate. go remove some elements. slay πβ¨π
π¦ 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