Redis Zrange Command
Redis Zrange returns the members in the specified interval in the sorted set.
The members are ordered by increasing score value (from small to large).
Members with the same score value are arranged in lexicographical order.
If you need members to be arranged by
descending value (from large to small), use theZREVRANGEcommand.
The subscript parameters start and stop are both 0-based, that is, 0 represents the first member of the sorted set, 1 represents the second member, and so on.
You can also use negative subscripts, with -1 representing the last member, -2 representing the second-to-last member, and so on.
Syntax
The basic syntax of the Redis Zrange command is as follows:
redis 127.0.0.1:6379> ZRANGE key start stop [WITHSCORES]
Available versions
>= 1.2.0
Return value
A list of members in the specified interval, with score values (optional).
Example
redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES # 显示整个有序集成员 1) "jack" 2) "3500" 3) "tom" 4) "5000" 5) "boss" 6) "10086" redis 127.0.0.1:6379> ZRANGE salary 1 2 WITHSCORES # 显示有序集下标区间 1 至 2 的成员 1) "tom" 2) "5000" 3) "boss" 4) "10086" redis 127.0.0.1:6379> ZRANGE salary 0 200000 WITHSCORES # 测试 end 下标超出最大下标时的情况 1) "jack" 2) "3500" 3) "tom" 4) "5000" 5) "boss" 6) "10086" redis > ZRANGE salary 200000 3000000 WITHSCORES # 测试当给定区间不存在于有序集时的情况 (empty list or set)
Other extensions
