Redis Lrem Command
Redis Lrem removes elements in the list that are equal to the parameter VALUE, based on the value of the parameter COUNT.
The COUNT value can be one of the following:
- count > 0 : Search from head to tail, remove elements equal to VALUE, with the number being COUNT.
- count < 0 : Search from tail to head, remove elements equal to VALUE, with the number being the absolute value of COUNT.
- count = 0 : Remove all values in the list that are equal to VALUE.
Syntax
The basic syntax of 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.
Examples
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>Other Extensions
Redis Lists