Redis zrangebyscore 命令用于返回排序集中在 key处介于最小值和最大值之间的所有元素。
返回结果的元素分数从低到高排序的。具有相同分数的元素按原集合顺序返回。
语法:
zrangebyscore key min max [WITHSCORES] [LIMIT offset count]
可用版本
>=1.0.5.
返回值
数组,指定分数范围内的元素列表(分数范围)。
返回值类型
数组
示例1:Redis zrangebyscore :指定分数的范围
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> zrangebyscore mysales -inf +inf WITHSCORES
1) "Samsung"
2) "1556"
3) "MicroSoft"
4) "1800"
5) "Micromax"
6) "1800"
7) "Nokis"
8) "2000"
9) "Sunsui"
10) "2200"
11) "LG"
12) "2500"
127.0.0.1:6379> zrangebyscore mysales 1500 1800 WITHSCORES
1) "Samsung"
2) "1556"
3) "MicroSoft"
4) "1800"
5) "Micromax"
6) "1800"
127.0.0.1:6379> zrangebyscore mysales 2000 +inf WITHSCORES
1) "Nokis"
2) "2000"
3) "Sunsui"
4) "2200"
5) "LG"
6) "2500"
示例2:Redis zrangebyscore
127.0.0.1:6379> zrangebyscore mysales (1500 (1800 WITHSCORES
1) "Samsung"
2) "1556"
127.0.0.1:6379> zrangebyscore mysales (1800 2200 WITHSCORES
1) "Nokis"
2) "2000"
3) "Sunsui"
4) "2200"
示例3:Redis zrangebyscore
127.0.0.1:6379> zrangebyscore mysales -inf +inf WITHSCORES LIMIT 0 3
1) "Samsung"
2) "1556"
3) "MicroSoft"
4) "1800"
5) "Micromax"
6) "1800"
127.0.0.1:6379> zrangebyscore mysales -inf +inf WITHSCORES LIMIT 4 10
1) "Sunsui"
2) "2200"
3) "LG"
4) "2500"