English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Redis Sorted Sets (sorted set)
Redis Zrange returns members in the specified range of the sorted set.
The position of the members is sorted in ascending order of the score value.
Members with the same score value are sorted in lexicographical order (lexicographical order).
If you need the members to be sorted by
Arranged in descending order (from large to small), please use ZREVRANGE command.
The index parameters start and stop are both base 0, which means that 0 represents the first member of the sorted set, with 1 to represent the second member, and so on.
You can also use negative indices, with -1 represents the last member, -2 represents the second-to-last member, and so on.
Basic Syntax of redis Zrange Command is as follows:
redis 127.0.0.1:6379> ZRANGE key start stop [WITHSCORES]
>= 1.2.0
List of sorted set members within the specified range, with score values (optional).
redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES # Display the entire sorted set members 1) "jack" 2) "3500 3) "tom" 4) "5" 5) "boss" 6) "10086" redis 127.0.0.1:6379> ZRANGE salary 1 2 WITHSCORES # Display the members of the sorted set index range 1 to 2 members 1) "tom" 2) "5" 3) "boss" 4) "10086" redis 127.0.0.1:6379> ZRANGE salary 0 200000 WITHSCORES # Test when the end index exceeds the maximum index 1) "jack" 2) "3500 3) "tom" 4) "5" 5) "boss" 6) "10086" redis > ZRANGE salary 200000 3000000 WITHSCORES # Test when the given range does not exist in the sorted set (empty list or set)