Redis Lrem Command
Redis Lrem removes elements equal to VALUE from the list according to the value of the COUNT argument.
The value of COUNT can be one of the following:
- count > 0: search from the head to the tail, removing up to COUNT elements equal to VALUE.
- count < 0: search from the tail toward the head, removing elements equal to VALUE, with the number of removals being the absolute value of COUNT.
- count = 0: remove all elements equal to VALUE from the list.
Syntax
The basic syntax of the redis Lrem command is as follows:
redis 127.0.0.1:6379> LREM key count VALUE
Available Version
= 1.0.0
Return Value
The number of removed elements. Returns 0 when the list does not exist.
Example
redis> RPUSH mylist "hello"
(integer) 1
redis> RPUSH mylist "hello"
(integer) 2
redis> RPUSH mylist "foo"
(integer) 3
redis> RPUSH mylist "hello"
(integer) 4
redis> LREM mylist -2 "hello"
(integer) 2
redis> LRANGE mylist 0 -1
1) "hello"
2) "foo"
redis>
Redis List