python redis list操作
2017-01-15 14:15
441 查看
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
将源队列中最右侧的数据弹出,并插入目的队列的最左侧,同时作为返回值,没有值得时候会阻塞
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
将源队列中最右侧的数据弹出,并插入目的队列的最左侧,同时作为返回值,没有值得时候会阻塞
相关文章推荐
- 2.Python操作Redis:列表(List)
- python3 操作 redis List(列表) 实例 详解
- python操作 redis-list
- Python操作redis系列之 列表(list) (五)
- 31. Python redis的字符串操作 list操作 set操作
- Python list 操作
- Python 列表(list)操作
- python list操作
- [Python]两个list对应元素操作(相减)
- Python操作redis
- python中list操作详解
- Python 区分List和一维数组的不同操作
- python中的list如何进行相减操作或者将list分片
- python list操作 - 转
- python的list操作
- python的list操作
- Python中的基本list操作
- redis:list数据类型与操作
- python中的list如何进行相减操作或者将list分片
- python操作redis简单例子