Q:

Redis zrange and zrangebyscore

Are these 2 Redis commands different, except for the second having optional LIMIT argument?
http://redis.io/commands/zrange
http://redis.io/commands/zrangebyscore

A:

They are different:

ZRANGE key start stop ...: start and stop are zero-based indexes (i.e they correspond to a position of an element within the sorted set),
ZRANGEBYSCORE key min max ...: min and max refer to scores (i.e they are used to specify a score range).

So, the first one operates by indexes while the second one (as its name implies) operates by scores. Thus they are used for different purposes.

A:

say, the sorted set is:
value score
tom 0
bob 1
alice 100
lucy 102

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"

this is the key difference.

