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
。