这两个Redis命令是否不同,除了第二个具有可选LIMIT参数?
http://redis.io/commands/zrange
http://redis.io/commands/zrangebyscore
del*_*eil 17
它们是不同的:
ZRANGE key start stop ...:start并且stop是从零开始的索引(即它们对应于有序集合中元素的位置),ZRANGEBYSCORE key min max ...:min并max参考分数(即它们用于指定分数范围).因此,第一个按索引操作,而第二个(顾名思义)按分数操作.因此,它们用于不同的目的.
说,排序集是:
value score
tom 0
bob 1
alice 100
lucy 102
Run Code Online (Sandbox Code Playgroud)
when you use zrangebyscores, and the max score is 2, the min score is 0, then, you will get tom and bob;
when you use zrange, and the start is 0, the stop is 2, then you will get tom, bob and alice.
127.0.0.1:6379> zadd example 0 tom 1 bob 100 alice 102 lucy
127.0.0.1:6379> zrange example 0 2 WITHSCORES
1) "tom"
2) "0"
3) "bob"
4) "1"
5) "alice"
6) "100"
127.0.0.1:6379> zrangebyscore example 0 2 WITHSCORES
1) "tom"
2) "0"
3) "bob"
4) "1"
Run Code Online (Sandbox Code Playgroud)
this is the key difference.
| 归档时间: |
|
| 查看次数: |
3277 次 |
| 最近记录: |