Redis - List Lrem Command


Advertisements

Redis LREM command removes the first count occurrences of elements equal to the value from the list stored at the key. The count argument influences the operation in the following ways −

  • count > 0 − Removes the elements equal to the value moving from the head to tail.

  • count < 0 − Removes the elements equal to the value moving from the tail to head.

  • count = 0 − Removes all elements equal to value.

Return Value

Integer reply, the number of removed elements.

Syntax

Following is the basic syntax of Redis LREM command.

redis 127.0.0.1:6379> LREM KEY_NAME COUNT VALUE 

Example

redis 127.0.0.1:6379> RPUSH mylist "hello" 
(integer) 1 
redis 127.0.0.1:6379> RPUSH mylist "hello" 
(integer) 2 
redis 127.0.0.1:6379> RPUSH mylist "foo" 
(integer) 3 
redis 127.0.0.1:6379> RPUSH mylist "hello" 
(integer) 4 
redis 127.0.0.1:6379> LREM mylist -2 "hello" 
(integer) 2
redis_lists.htm
Advertisements