LREM
LREM key count element
- Group
- List
- Complexity
- O(N+M) where N is the length of the list and M is the number of elements removed
- Arity
- 4 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
LREM removes elements equal to element from the list stored at key.
count controls how many and from which end:
count > 0: remove up tocountoccurrences, scanning from the head.count < 0: remove up to|count|occurrences, scanning from the tail.count = 0: remove every occurrence.
When the list becomes empty, the key is deleted.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the number of elements removed | Same |
| Key does not exist | Integer 0 |
Same |
Errors:
ERR value is not an integer or out of rangeifcountis not an integer.ERR value is out of range, value must between -9223372036854775807 and 9223372036854775807for acountof -9223372036854775808.WRONGTYPEifkeyholds a value that is not a list.
count is checked before the key is looked up.
Examples
Section titled “Examples”127.0.0.1:6379> RPUSH items a b a c a(integer) 5127.0.0.1:6379> LREM items -2 a(integer) 2127.0.0.1:6379> LRANGE items 0 -11) "a"2) "b"3) "c"127.0.0.1:6379> LREM items 0 a(integer) 1Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.