1.将值追加到清單
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
127.0.0.1:6379> llen mylist
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" #清單目前第一個值
1) "mylist"
2) "value2"
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
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
7.在清單一個元素的之前或之後插入一個元素,傳回目前清單的長度
linsert key before|after pivot value
summary: insert an element before or after another element in a list
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
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
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
11.擷取指定範圍的list的value值
lrange key start stop
summary: get a range of elements from a list
12.從清單中移除元素(當list中存在多個重複的值時,count确定要移除幾個value)
lrem key count value
summary: remove elements from a list
13.通過元素的索引index設定value
lset key index value
summary: set the value of an element in a list by its index
127.0.0.1:6379> lset list2 3 namew #修改第三個位置的值
ok
14.
ltrim key start stop
summary: trim a list to the specified range
15.移除并擷取清單中的最後一個元素
rpop key
summary: remove and get the last element in a list
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