Latest web development tutorials

Redis Lrem command

Redis list (List)

Redis Lrem based on the value of the parameter COUNT, remove the list parameter VALUE equal elements.

COUNT value may be the following:

  • count> 0: Start from the head to the tail of the table search, remove and VALUE equal elements, the number of COUNT.
  • count <0: Header began to search from the tail, remove the VALUE equal elements, the number of the absolute value of COUNT.
  • count = 0: remove all the values ​​in the table with the VALUE equal.

grammar

redis Lrem basic command syntax is as follows:

redis 127.0.0.1:6379> LREM KEY_NAME COUNT VALUE

Available versions

> = 1.0.0

return value

The number of elements to be removed. Return 0 if the list does not exist.

Examples

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 list (List)