Redis ZREVRANGE令

9个月前 (04-27)
Redis ZREVRANGE 令返回有序集 key 中,指定区间内的成员。其中成员的位置按 score 值递减(从大到小)来排列。具有相同 score 值的成员按字典序的逆序排列。

除了成员按 score 值降序排列外, ZREVRANGE 令的其他方面和 ZRANGE 令相同。

可用版本

ZREVRANGE 令可用版本:>= 1.2.0

语法

Redis ZREVRANGE 令的基本语法如下:

ZREVRANGE key start stop [WITHSCORES] 

返回值

指定区间内,带有 score 值(可选)的有序集成员的列表。

令演示

127.0.0.1:6379> ZADD salary 3000 jack 3500 helen 2880

(integer) 3

127.0.0.1:6379> ZRANGE salary 0 -1 withscores

1) "john"

2) "2880"

3) "jack"

4) "3000"

5) "helen"

6) "3500"

127.0.0.1:6379> ZREVRANGE salary 0 -1 withscores

1) "helen"

2) "3500"

3) "jack"

4) "3000"

5) "john"

6) "2880"