Redis(六):数据结构之SortSet 常用命令

SortSet 

key ->{ key , sorce}

1.ZADD

127.0.0.1:6379> ZADD scoreset 10 java 9 python 8 go 22 js
(integer) 4

2.ZCOUNT 分数区间数量

127.0.0.1:6379> zcount scoreset 0 10
(integer) 3

3.ZSCORE 获取得分

127.0.0.1:6379> ZSCORE scoreset java
"10"

4.ZINCRBY 增加
5.ZCARD 总数量
6.ZRANGE 获取set 

127.0.0.1:6379> ZRANGE scoreset 0 -1
1) "go"
2) "python"
3) "java"
4) "js" 


7.ZREVRANGE 按分数降序

127.0.0.1:6379> ZREVRANGE scoreset 0 -1
1) "js"
2) "java"
3) "python"
4) "go"


8.ZRANGEBYSCORE 只获取分数区间元素 不排序

5<=score<=10
127.0.0.1:6379> ZRANGEBYSCORE scoreset 5 10
1) "go"
2) "python"
3) "java"
5<=score<10
127.0.0.1:6379> ZRANGEBYSCORE scoreset 5 (10
1) "go"
2) "python"

9.ZREVRANGEBYSCORE 获取分数区间元素 并降序

127.0.0.1:6379> ZREVRANGEBYSCORE scoreset 10 5
1) "java"
2) "python"
3) "go"

10.ZRANK 排名  最大第一名

127.0.0.1:6379> ZRANK scoreset js
(integer) 3

11.ZREVRANK  0表示第一名

127.0.0.1:6379> ZRevrank scoreset js
(integer) 0

 

你可能感兴趣的:(数据库,Redis)