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
将源队列中最右侧的数据弹出,并插入目的队列的最左侧,同时作为返回值,没有值得时候会阻塞