range

UK[reɪndʒ] US[rendʒ]

n.Range; range; category; (mountains, houses, etc.) arrangement

vi.Search; change; extend; roam

vt. Arrange; (according to a certain position or order) sort; classify...; wander

adj. pasture, grazing area

Third person singular: ranges Plural: ranges Present participle: ranging Past tense: ranged Past participle: ranged

redis ZRANGE command syntax

Function: Returns the members in the specified range in the ordered set key. The positions of the members are sorted by increasing score value (from small to large). Members with the same score value are arranged in lexicographical order.

Syntax: ZRANGE key start stop [WITHSCORES]

Instructions: If you need members to come by decreasing score value (from large to small) To arrange, use the ZREVRANGE command. The subscript parameters start and stop are both base 0, that is, 0 represents the first member of the ordered set, 1 represents the second member of the ordered set, 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. Out-of-range subscripts do not cause an error. For example, when the value of start is greater than the maximum index of the sorted set, or when start > stop , the ZRANGE command simply returns an empty list. On the other hand, if the value of the stop parameter is greater than the maximum subscript of the sorted set, then Redis will treat stop as the maximum subscript. You can use the WITHSCORES option to return the member along with its score value. The returned list is in the format of value1,score1, ..., valueN,scoreN. The client library may return some more complex data types, such as arrays, tuples, etc.

Available versions: >= 1.2.0

Time complexity: O(log(N) M), N is ordered The cardinality of the set, and M is the cardinality of the result set.

Returns: A list of ordered set members with score value (optional) in the specified interval.

redis ZRANGE command example

redis > ZRANGE salary 0 -1 WITHSCORES             # 显示整个有序集成员
1) "jack"
2) "3500"
3) "tom"
4) "5000"
5) "boss"
6) "10086"
redis > ZRANGE salary 1 2 WITHSCORES              # 显示有序集下标区间 1 至 2 的成员
1) "tom"
2) "5000"
3) "boss"
4) "10086"
redis > 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)