修改本页

Redis 命令 客户端 文档 社区 下载 问题 支持 许可

LREM key count value

相关命令

始于1.0.0可用。

时间复杂度: O(N) where N is the length of the list.

Removes the first count occurrences of elements equal to value from the list stored at key. The count argument influences the operation in the following ways:

  • 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.

For example, LREM list -2 "hello" will remove the last two occurrences of "hello" in the list stored at list.

Note that non-existing keys are treated like empty lists, so when key does not exist, the command will always return 0.

返回值

Integer reply: the number of removed elements.

例子

redis> RPUSH mylist "hello"

  1. (integer) 1

redis> RPUSH mylist "hello"

  1. (integer) 2

redis> RPUSH mylist "foo"

  1. (integer) 3

redis> RPUSH mylist "hello"

  1. (integer) 4

redis> LREM mylist -2 "hello"

  1. (integer) 2

redis> LRANGE mylist 0 -1

  1. 1) "hello"
  2. 2) "foo"
redis>

Comments powered by Disqus

This website is open source software developed by Citrusbyte.

The Redis logo was designed by Carlos Prioglio. See more credits.

Sponsored by Redis Support