Redis - LREM 命令



Redis LREM 命令會從儲存在鍵中的列表中,移除第一個與值相等的 count 個元素。count 引數會對操作產生如下影響:-

  • count > 0 - 從頭部到尾部移除與值相等的元素。

  • count < 0 - 從尾部到頭部移除與值相等的元素。

  • count = 0 - 移除所有與值相等的元素。

返回值

整數形式的回覆,表示已移除的元素數量。

語法

以下是 Redis LREM 命令的基本語法。

redis 127.0.0.1:6379> LREM KEY_NAME COUNT VALUE 

示例

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_lists.htm
廣告