Redis zset

zset操作
1.不重复
2.有序
3.可以排序

添加
127.0.0.1:6379> zadd apple 1 chun 2 xia 3 qiu 4 dong
(integer) 4
取值
127.0.0.1:6379> zrange apple 0 -1
1) "chun"
2) "xia"
3) "qiu"
4) "dong"

得到元素数量
127.0.0.1:6379> zcard apple
(integer) 4

获取满足条件的数据个数
127.0.0.1:6379> zcount apple 2 3
(integer) 2

给指定的值的分数增加分数
(把秋的值加上10,如果不存在就创建)
127.0.0.1:6379> zincrby apple 10 qiu
"13"

查询数据,带分数的
127.0.0.1:6379> zrange xxx 0 -1 withscores
1) "goods.1"
2) "1"
3) "goods.2"
4) "2"

倒叙
127.0.0.1:6379> zrevrange xxx 0 -1 withscores
1) "goods.2"
2) "2"
3) "goods.1"
4) "1"

倒叙取出前三
127.0.0.1:6379> zrevrange xxx 0 2 withscores
1) "goods.7"
2) "8"
3) "goods.3"
4) "4"
5) "goods.2"
6) "2"

取成员的分数值
127.0.0.1:6379> zscore xxx goods.2
"2"

移除某个成员
127.0.0.1:6379> zrem xxx goods.2
(integer) 1

猜你喜欢

转载自www.cnblogs.com/songfahzun/p/8969270.html

相关文章