Redis Lrem Command
Redis Lrem removes elements from the list that match the VALUE parameter, based on the COUNT parameter.
The COUNT value can be:
count > 0: Search from the head to the tail of the list, removing elements equal to VALUE, up to COUNT occurrences.
count < 0: Search from the tail to the head of the list, removing elements equal to VALUE, up to the absolute value of COUNT occurrences.
count = 0: Remove all elements in the list that are equal to VALUE.
Syntax
The basic syntax for the redis Lrem command is as follows:
redis 127.0.0.1:6379> LREM key count VALUE
Available Versions
= 1.0.0
Return Value
The number of removed elements. Returns 0 if 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>