redis命令操作list
- 列表类型 list:可以添加一个元素列表的头部(左边)或者尾部(右边)
- 添加:
- lpush key value:将元素加入列表左边
- rpush key value:将元素加入列表右边
- 获取:
- lrange key start end :获取范围
- 删除:
- lpop key :删除列表最左边的元素,并将元素返回
- rpop key:删除列表最右边的元素,并将元素返回
- 添加:
127.0.0.1:6379> lpush mylist a
(integer) 1
127.0.0.1:6379> lpush mylist b
(integer) 2
127.0.0.1:6379> rpush mylist c
(integer) 3
127.0.0.1:6379> lpush mylist d
(integer) 4
127.0.0.1:6379> lrange mylist 0 -1
1) "d"
2) "b"
3) "a"
4) "c"
127.0.0.1:6379> lpop mylist
"d"
127.0.0.1:6379> lrange mylist 0 -1
1) "b"
2) "a"
3) "c"
127.0.0.1:6379> rpop mylist
"c"
127.0.0.1:6379> lrange mylist 0 -1
1) "b"
2) "a"
127.0.0.1:6379>
redis命令操作set&sortedset
- 集合类型set:不允许重复元素
- 存储:sadd key value
- 获取:smember key:获取set列表中所有元素
- 删除:srem key value:删除set集合中的某个元素
127.0.0.1:6379> SADD myset a
(integer) 1
127.0.0.1:6379> SADD myset a
(integer) 0
127.0.0.1:6379> SMEMBERS myset
1) "a"
127.0.0.1:6379> SADD myset b c d
(integer) 3
127.0.0.1:6379> SMEMBERS myset
1) "d"
2) "c"
3) "b"
4) "a"
127.0.0.1:6379> SADD myset e
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "d"
2) "c"
3) "b"
4) "a"
5) "e"
127.0.0.1:6379> SADD myset f g h
(integer) 3
127.0.0.1:6379> SMEMBERS myset
1) "a"
2) "f"
3) "b"
4) "g"
5) "d"
6) "c"
7) "e"
8) "h"
127.0.0.1:6379> SREM myset a
(integer) 1
127.0.0.1:6379> SMEMBERS myset
1) "f"
2) "b"
3) "g"
4) "d"
5) "c"
6) "e"
7) "h"
127.0.0.1:6379>
- 有序集合类型 sortedset:不允许重复元素,且元素有顺序
- 存储:zadd key score value
- 获取:zrange key start end
- 删除:zren key value
127.0.0.1:6379> ZADD mysort 1 zhangsan
(integer) 1
127.0.0.1:6379> ZADD mysort 3 wangwu
(integer) 1
127.0.0.1:6379> ZRANGE mysort 0 -1
1) "zhangsan"
2) "wangwu"
127.0.0.1:6379> ZADD mysort 2 lisi
(integer) 1
127.0.0.1:6379> zrange mysort 0 -1
1) "zhangsan"
2) "lisi"
3) "wangwu"
127.0.0.1:6379> ZRANGE mysort 0 -1 withscorees
(error) ERR syntax error
127.0.0.1:6379> ZRANGE mysort 0 -1 withscores
1) "zhangsan"
2) "1"
3) "lisi"
4) "2"
5) "wangwu"
6) "3"
127.0.0.1:6379> zadd mysort 500 zhaoliu
(integer) 1
127.0.0.1:6379> ZRANGE mysort 0 -1 withscores
1) "zhangsan"
2) "1"
3) "lisi"
4) "2"
5) "wangwu"
6) "3"
7) "zhaoliu"
8) "500"
127.0.0.1:6379> zrem mysort lisi
(integer) 1
127.0.0.1:6379> ZRANGE mysort 0 -1 withscores
1) "zhangsan"
2) "1"
3) "wangwu"
4) "3"
5) "zhaoliu"
6) "500"
127.0.0.1:6379>
标签:set,6379,0.1,myset,redis,命令,127.0,mysort,integer
From: https://www.cnblogs.com/ailhy/p/16611873.html