YouTip LogoYouTip

Sorted Sets Zrange

# Redis Zrange Command * (javascript:void(0);) * (javascript:void(0);) * (javascript:void(0);) * (javascript:void(0)) Redis Tutorial (#)(#)(#)(#)(#) ## Redis Commands (#)(#)(#)(#)(#)(#)(#)(#)[Redis Pub/Sub](#)(#)(#)(#)(#)(#)(#) ## Redis Advanced Tutorial [Redis Data Backup & Recovery](#)(#)(#)(#)(#)(#)(#)(#) [](#)(#) (#)[](#) Deep Dive Development Tools Web Service Network Design & Development Computer Science Software Scripting Web Services Scripting Languages Programming Languages Programming # Redis Zrange Command !(#)(#) The Redis Zrange command returns a list of members within a specified range in a sorted set. Members are ordered by score in ascending order (from lowest to highest). Members with the same score are ordered lexicographically. If you need members ordered by score in descending order (from highest to lowest), use the (#) command. The index parameters `start` and `stop` are zero-based, meaning 0 represents the first member of the sorted set, 1 represents the second member, and so on. You can also use negative indices, where -1 represents the last member, -2 represents the second-to-last member, and so on. ### Syntax The basic syntax for the Redis Zrange command is: redis 127.0.0.1:6379> ZRANGE key start stop ### Available Since >= 1.2.0 ### Return Value A list of members in the specified range, with their scores (optional). ### Examples redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES # Display all members of the sorted set1) "jack"2) "3500"3) "tom"4) "5000"5) "boss"6) "10086" redis 127.0.0.1:6379> ZRANGE salary 1 2 WITHSCORES # Display members in index range 1 to 2 of the sorted set1) "tom"2) "5000"3) "boss"4) "10086" redis 127.0.0.1:6379> ZRANGE salary 0 200000 WITHSCORES # Test when the end index exceeds the maximum index1) "jack"2) "3500"3) "tom"4) "5000"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) !(#)(#)
← Jsref IfC Function Cosh β†’