redis LREM command


  Translation results:

rem

UK[ˌɑ:r i: ˈem] US[ˌɑ:ri:'em]

n.DOS command: Specify the command line ignored by DOS; (sleep) fast

of eye movements

redis LREM commandsyntax

Function: According to the value of parameter count, remove elements from the list that are equal to parameter value.

Syntax: LREM key count value

Available versions:>= 1.0.0

Time complexity Degree: O(N), N is the length of the list.

Returns: The number of removed elements. Because a non-existing key is considered an empty list, the LREM command always returns 0 when the key does not exist.

redis LREM commandexample

# 先创建一个表,内容排列是
# morning hello morning helllo morning
redis> LPUSH greet "morning"
(integer) 1
redis> LPUSH greet "hello"
(integer) 2
redis> LPUSH greet "morning"
(integer) 3
redis> LPUSH greet "hello"
(integer) 4
redis> LPUSH greet "morning"
(integer) 5
redis> LRANGE greet 0 4         # 查看所有元素
1) "morning"
2) "hello"
3) "morning"
4) "hello"
5) "morning"
redis> LREM greet 2 morning     # 移除从表头到表尾,最先发现的两个 morning
(integer) 2                     # 两个元素被移除
redis> LLEN greet               # 还剩 3 个元素
(integer) 3
redis> LRANGE greet 0 2
1) "hello"
2) "hello"
3) "morning"
redis> LREM greet -1 morning    # 移除从表尾到表头,第一个 morning
(integer) 1
redis> LLEN greet               # 剩下两个元素
(integer) 2
redis> LRANGE greet 0 1
1) "hello"
2) "hello"
redis> LREM greet 0 hello      # 移除表中所有 hello
(integer) 2                    # 两个 hello 被移除
redis> LLEN greet
(integer) 0

Home

Videos

Q&A