声明:学习笔记,有错希指正、
下面节扫了基本的增删改的操作以及阻塞弹出命令和弹出并推入命令,最常见的是消息传递(messageing)和任务队列(task queue),这个以后再介绍
命令 | 操作 |
---|---|
rpush | 将一个或者多个值推入列表的右端 |
lpush | 将一个或者多个值推入列表的端 |
rpop | 移除最右边的元素 |
lpop | 移除最左边的元素 |
lindex | 查询某个偏移量的值 |
lrange | 查找某个偏移量范围内的数据 |
ltrim | 截取某个范围内的值,其他的没在这个范围内的数据删掉 |
blpop | 从第一个非空列表中弹出最左端的元素,或者在timeout秒内等待可以弹出的元素出现 |
brpop | 从第一个非空列表中弹出最右端的元素,或者在timeout秒内等待可以弹出的元素出现 |
rpoplpush | rpoplpush source-key dest-key 把source-key里面最右端的元素弹出加到dest-key的最左端 |
brpoplpush | rpoplpush source-key dest-key 把source-key里面最右端的元素弹出加到dest-key的最左端,如果source-key为空,在timeout秒内等待可以弹出的元素出现 |
redis 127.0.0.1:6379> rpush mylist-key hello
(integer) 1
redis 127.0.0.1:6379> rpush mylist-key world
(integer) 2
redis 127.0.0.1:6379> lindex mylist-key 0
"hello"
redis 127.0.0.1:6379> lindex mylist-key 1
"world"
redis 127.0.0.1:6379> lrange mylist-key 0 1
1) "hello"
2) "world"
redis 127.0.0.1:6379> lpush mylist-key hi
(integer) 3
redis 127.0.0.1:6379> lrange mylist-key 0 2
1) "hi"
2) "hello"
3) "world"
redis 127.0.0.1:6379> ltrim mylist-key 1 2
OK
redis 127.0.0.1:6379> lrange mylist-key 0 1
1) "hello"
2) "world"
redis 127.0.0.1:6379>
--两个列表之间的操作
redis 127.0.0.1:6379> rpush list1 hello
(integer) 1
redis 127.0.0.1:6379> rpush list1 world
(integer) 2
redis 127.0.0.1:6379> rpush list1 !
(integer) 3
redis 127.0.0.1:6379> lrange list1 0 2
1) "hello"
2) "world"
3) "!"
redis 127.0.0.1:6379> rpush list2 test
(integer) 1
redis 127.0.0.1:6379> brpoplpush list2 list1 0
"test"
redis 127.0.0.1:6379> lrange list1 0 -1
1) "test"
2) "hello"
3) "world"
4) "!"
--移动成功啦