LPUSH list_name value [value ...]
Prepend one or multiple values to a list
從左側插入值,最早插入的值在最右邊
LPUSHX list_name value
Prepend a value to a list, only if the list exists
判斷列表是否存在,如果存在就插入值,不存在就不插入值,只能插入一次,從左邊插入
LINSERT list_name BEFORE|AFTER pivot value
Insert an element before or after another element in a list
r.linsert('list1', 'before', 6, 7)
在列表的某個值前面或者后面插入新的值,因為是從左側計算,所以前面就是左側,后面就是右側
RPUSH list_name value [value ...]
Append one or multiple values to a list
r.rpush('list1', 8, 9)
從列表右側插入值,可以一次插入多個
RPUSHX list_name value
Append a value to a list, only if the list exists
r.rpushx('list1', 9)
判斷列表是否存在,存在的話就從列表的右側插入值,一次只能插入一個,不存在就不能創建
LPOP list_name
Remove and get the first element in a list
r.lpop('list1')
從列表的最左側返回元素
RPOP key
Remove and get the last element in a list
r.rpop('list1')
從列表的最右側返回元素
BLPOP list_name1 [list_name2 ...] timeout
Remove and get the first element in a list, or block until one is available
如果操作的列表不存在就是會阻塞住
r.blpop('list2')
r.blpop(["list1","list2"])
r.blpop(["list1","list2"], 100)
取出隊列列表中不空隊列的最左側元素,如果都是為空,那就阻塞
BRPOP list_name1 [list_name2 ...] timeout
Remove and get the last element in a list, or block until one is available
如果操作的列表不存在就是會阻塞住
r.brpop('list2')
r.brpop(["list1","list2"])
r.brpop(["list1","list2"], 100)
取出隊列列表中不空隊列的最右側元素,如果都是為空,那就阻塞
LSET list_name index value
Set the value of an element in a list by its index
r.lset('list1', 0, 999)
設置隊列指定下標的值
LINDEX list_name index
Get an element from a list by its index
r.lindex('list1', 1)
獲取隊列中指定下標的值
LRANGE list_name start stop
Get a range of elements from a list
r.lrange('list1', 0, 3)
獲取隊列中指定范圍的值
LLEN list_name
Get the length of a list
r.llen('list1')
獲取隊列長度
LREM list_name value count
Remove elements from a list
r.lrem('list1', 999, 0)
刪除隊列中的指定值
name: redis的list名稱
value: 要刪除的值
num: num=0 刪除列表中所有的指定值;
num=2 從前到后,刪除2個;
num=-2 從后向前,刪除2個'''
LTRIM list_name start stop
Trim a list to the specified range
r.ltrim('list1', 0, 1)
移除列表內沒有在該索引之內的值
RPOPLPUSH source destination
Remove the last element in a list, prepend it to another list and return it
r.rpoplpush('list1', 'list2')
將源隊列中最右側的數據彈出,並插入目的隊列的最左側,同時作為返回值
BRPOPLPUSH source destination timeout
Pop a value from a list, push it to another list and return it; or block until one is available
將源隊列中最右側的數據彈出,並插入目的隊列的最左側,同時作為返回值,沒有值得時候會阻塞