English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis Lrem Command

Redis Lists (List)

Redis Lrem removes elements equal to the parameter VALUE from the list according to the parameter COUNT.

The value of COUNT can be one of the following types:

  • count > 0 : Start from the head of the table and search towards the end, remove elements equal to VALUE, the number of elements to remove is COUNT.

  • count < 0 : Start from the end of the table and search towards the head, remove elements equal to VALUE, the number of elements to remove is the absolute value of COUNT.

  • count = 0 : Remove all values equal to VALUE in the table.

Syntax

Basic Syntax of Redis Lrem Command

redis 127.0.0.1:6379> LREM key count VALUE

Available Version

>= 1.0.0

Return value

The number of elements removed. Returns 0 when the list does not exist.

Online 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>

Redis Lists (List)