RPUSH key value [value ...]
summary: Append one or multiple values to a list
since: 1.0.0
127.0.0.1:6379> RPUSH mylist value1 value2 value3
(integer) 3
2.獲取列表的長度
LLEN key
summary: Get the length of a list
since: 1.0.0
127.0.0.1:6379> llen mylist
(integer) 3
3.獲取並移除列表中第一個元素
BLPOP key [key ...] timeout
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0
127.0.0.1:6379> blpop mylist 3
1) "mylist" ##列表key
2) "value1" #列表當前第一個值
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value2"
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value3"
127.0.0.1:6379> blpop mylist 3 列表已經不存在value
(nil)
(3.78s)
4.獲取並移除列表中的最後一個元素
BRPOP key [key ...] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0
127.0.0.1:6379> brpop list1 3
1) "list1" #列表鍵名
2) "value3" #列表最後一個值
5.出棧list中的一個value,並放入另一個list中,並返回該值
BRPOPLPUSH source destination timeout
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0
127.0.0.1:6379> BRPOPLPUSH list1 list2 3
"value2"
6.獲取指定位置的value值,返回的是該位置的值,無值或超出邊界返回nil
LINDEX key index
summary: Get an element from a list by its index
since: 1.0.0
7.在列表一個元素的之前或之後插入一個元素,返回當前列表的長度
LINSERT key BEFORE|AFTER pivot value
summary: Insert an element before or after another element in a list
since: 2.2.0
127.0.0.1:6379> linsert ml before v2 value2
(integer) 5 在v2之前插入值value2
8.棧頂元素出棧
LPOP key
summary: Remove and get the first element in a list
since: 1.0.0
127.0.0.1:6379> lpop ml
"v1"
9.向list中添加一個或多個value,後加入的值,index在前(將元素壓入棧頂)
LPUSH key value [value ...]
summary: Prepend one or multiple values to a list
since: 1.0.0
127.0.0.1:6379> lpush list2 val1 val2 val3 val4 val5
(integer) 6
127.0.0.1:6379> lindex list2 0
"val5"
10.只有當列表存在時,才從棧頂壓入元素
LPUSHX key value
summary: Prepend a value to a list, only if the list exists
since: 2.2.0
11.獲取指定範圍的list的value值
LRANGE key start stop
summary: Get a range of elements from a list
since: 1.0.0
12.從列表中移除元素(當list中存在多個重複的值時,count確定要移除幾個value)
LREM key count value
summary: Remove elements from a list
since: 1.0.0
13.通過元素的索引index設置value
LSET key index value
summary: Set the value of an element in a list by its index
since: 1.0.0
127.0.0.1:6379> lset list2 3 namew #修改第三個位置的值
OK
14.
LTRIM key start stop
summary: Trim a list to the specified range
since: 1.0.0
15.移除並獲取列表中的最後一個元素
RPOP key
summary: Remove and get the last element in a list
since: 1.0.0
16.移除列表中的最後一個元素,追加到另一個列表中,並返回該值
RPOPLPUSH source destination
summary: Remove the last element in a list, append it to another list and return it
since: 1.2.0
17.將值追加到列表中,只有當這個列表已經存在
RPUSHX key value
summary: Append a value to a list, only if the list exists
since: 2.2.0