Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Lrem Command

Redis Lrem Command

Redis List

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:

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