Redis zrevrangebyscore 命令用于返回在 key 处的排序集中分数介于最大值和最小值之间的所有元素,其元素分数为从高到低依次排序。
语法:
zrevrangebyscore key max min [WITHSCORES] [LIMIT offset count]
返回值
数组,指定分数范围内的元素列表(可选分数)。
示例1:Redis zrevrangebyscore
127.0.0.1:6379> zadd mysales 1556 Samsung 2000 Nokis 1800 Micromax
(integer) 3
127.0.0.1:6379> zadd mysales 2200 Sunsui 1800 MicroSoft 2500 LG
(integer) 3
127.0.0.1:6379> zrevrangebyscore mysales +inf -inf WITHSCORES
1) "LG"
2) "2500"
3) "Sunsui"
4) "2200"
5) "Nokis"
6) "2000"
7) "Micromax"
8) "1800"
9) "MicroSoft"
10) "1800"
11) "Samsung"
12) "1556"
127.0.0.1:6379> zrevrangebyscore mysales 2000 1800 WITHSCORES
1) "Nokis"
2) "2000"
3) "Micromax"
4) "1800"
5) "MicroSoft"
6) "1800"
127.0.0.1:6379> zrevrangebyscore mysales +inf 2200 WITHSCORES
1) "LG"
2) "2500"
3) "Sunsui"
4) "2200"
示例2:Redis zrevrangebyscore
127.0.0.1:6379> zadd mysales 1556 Samsung 2000 Nokis 1800 Micromax
(integer) 3
127.0.0.1:6379> zadd mysales 2200 Sunsui 1800 MicroSoft 2500 LG
(integer) 3
127.0.0.1:6379> zrevrangebyscore mysales +inf -inf WITHSCORES
1) "LG"
2) "2500"
3) "Sunsui"
4) "2200"
5) "Nokis"
6) "2000"
7) "Micromax"
8) "1800"
9) "MicroSoft"
10) "1800"
11) "Samsung"
12) "1556"
127.0.0.1:6379> zrevrangebyscore mysales (2100 (1800 WITHSCORES
1) "Nokis"
2) "2000"
127.0.0.1:6379> zrevrangebyscore mysales 2100 (1800 WITHSCORES
1) "Nokis"
2) "2000"
示例3:Redis zrevrangebyscore
127.0.0.1:6379> zadd mysales 1556 Samsung 2000 Nokis 1800 Micromax
(integer) 3
127.0.0.1:6379> zadd mysales 2200 Sunsui 1800 MicroSoft 2500 LG
(integer) 3
127.0.0.1:6379> zrevrangebyscore mysales +inf -inf WITHSCORES
1) "LG"
2) "2500"
3) "Sunsui"
4) "2200"
5) "Nokis"
6) "2000"
7) "Micromax"
8) "1800"
9) "MicroSoft"
10) "1800"
11) "Samsung"
12) "1556"
127.0.0.1:6379> zrevrangebyscore mysales +inf -inf WITHSCORES LIMIT 0 3
1) "LG"
2) "2500"
3) "Sunsui"
4) "2200"
5) "Nokis"
6) "2000"
127.0.0.1:6379> zrevrangebyscore mysales +inf -inf WITHSCORES LIMIT 3 10
1) "Micromax"
2) "1800"
3) "MicroSoft"
4) "1800"
5) "Samsung"
6) "1556"