Sorted sets in redis syntax analysis

Time:2020-8-14

Set is K1 V1 V2 V3, Zset is K1 Score1 V1 score v2

1、 Increase

127.0.0.1:6379 > zadd zset01 60 V1 70 V2 // 60, 70 stands for score
(integer) 2

2、 Delete

127.0.0.1:6379 > zrem zset01 V1 // delete v1
(integer) 1

3、 Reform

127.0.0.1:6379> zrange zset01 0 -1 withscores
1) "v0"
2) "50"
3) "v2"
4) "70"
5) "v3"
6) "80"
127.0.0.1:6379 > zincrby zset01 5 V0 // add 5 to the score of v0
"55"

4、 Check

127.0.0.1:6379> zrange zset01 0 -1
1) "v1"
2) "v2"
3) "v3"
127.0.0.1:6379 > zrangebyscore zset01 60 70 // get a value between 60 and 70, containing both sides
1) "v1"
2) "v2"
0.0.1:6379 > zrangebyscore zset01 60 (70 // excluding 70)
1) "v1"
127.0.0.1:6379 > zcard zset01 // number of elements contained
(integer) 2
127.0.0.1:6379 > zcount zset01 60 75 // the number of scores between 60-75
(integer) 1
127.0.0.1:6379 > zrank zset01 V2 // get the index table below
(integer) 0
127.0.0.1:6379 > zscore zset01 V3 // get the score of V3
"80"
127.0.0.1:6379 > zrevrank zset01 V2 // get the index value after reverse order
(integer) 1
127.0.0.1:6379 > zrerange zset01 0 - 1 // output in reverse order
1) "v3"
2) "v2"
127.0.0.1:6379 > zrevrangebyscore zset01 90 60 // the output is reversed according to the fraction
1) "v3"
2) "v2"