ZRANGEBYscore:
功能:
返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。有序集成员按 score 值递增(从小到大)次序排列。
用法示例:
ZREVRANGEBYscore key max min [WITHscoreS] [LIMIT offset count]
参数解释:
key 键名
min 最小的score值
max 最大的score值
WITHscoreS 是否返回分值
LIMIT offset count 取值范围
区间及无限:
min 和 max 可以是 -inf 和 +inf
用法:
假设每个人薪水数据范围
redis 127.0.0.1:6379> ZADD salary 10086 jack (integer) 1 redis > ZADD salary 5000 tom (integer) 1 redis 127.0.0.1:6379> ZADD salary 7500 peter (integer) 1 redis 127.0.0.1:6379> ZADD salary 3500 joe (integer) 1
获取所有人薪水数据
redis 127.0.0.1:6379> ZREVRANGEBYscore salary +inf -inf # 逆序排列所有成员 1) "jack" 2) "peter" 3) "tom" 4) "joe"
获取薪水小于5500的数据
redis 127.0.0.1:6379> ZREVRANGEBYscore salary -inf 5000 # 排列薪水介于 最小值和 5500之间的成员 1) "joe" 2) "tom"
获取薪水大于5500的数据
redis 127.0.0.1:6379> ZREVRANGEBYscore salary 5500 +inf # 排列薪水介于 5500和 最大值之间的成员 1) "peter" 2) "jack"