LREM

Syntax
LREM key count element
Available since:
1.0.0
Time complexity:
O(N+M) where N is the length of the list and M is the number of elements removed.
ACL categories:
@write, @list, @slow,

从存储在key的列表中移除前count个等于element的元素。 count参数以以下方式影响操作:

  • count > 0: 从头部到尾部移除等于element的元素。
  • count < 0: 从尾部向头部移除等于 element 的元素。
  • count = 0: 移除所有等于 element 的元素。

例如,LREM list -2 "hello" 将移除存储在 list 中的最后两个 "hello" 出现。

请注意,不存在的键被视为空列表,因此当key不存在时,命令将始终返回0

示例

RPUSH mylist "hello" RPUSH mylist "hello" RPUSH mylist "foo" RPUSH mylist "hello" LREM mylist -2 "hello" LRANGE mylist 0 -1

RESP2/RESP3 回复

Integer reply: the number of removed elements.
RATE THIS PAGE
Back to top ↑