Redis Lists: LREM
LREM key count value
Redis LREM command is used to remove the first count occurrences of elements equal to the value from the list stored at key. The count argument influences the operation describes as below:
- count > 0: Remove elements equal to value moving from head to tail.
- count < 0: Remove elements equal to value moving from tail to head.
- count = 0: Remove all elements equal to value.
Syntax:
LREM KEY_NAME COUNT VALUE
Available since
1.0.0.
Return Value
Integer replies the number of removed elements.
Return Value Type
Integer
Example: Redis LREM
127.0.0.1:6379> LPUSH mycolor red red red green (integer) 4 127.0.0.1:6379> LRANGE mycolor 0 -1 1) "green" 2) "red" 3) "red" 4) "red" 127.0.0.1:6379> LREM mycolor 1 red (integer) 1 127.0.0.1:6379> LRANGE mycolor 0 -1 1) "green" 2) "red" 3) "red" 127.0.0.1:6379> LREM mycolor 0 red (integer) 2 127.0.0.1:6379> LRANGE mycolor 0 -1 1) "green"
Example: Redis LREM: When used in the right to delete from negative
127.0.0.1:6379> LPUSH mycolor red red red green (integer) 4 127.0.0.1:6379> LRANGE mycolor 0 -1 1) "green" 2) "red" 3) "red" 4) "red" 127.0.0.1:6379> LREM mycolor -2 red (integer) 2 127.0.0.1:6379> LRANGE mycolor 0 -1 1) "green" 2) "red"
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics