# ZREVRANGE

> Get a range of members from a sorted set by rank, highest score first.

URL: https://docs.hotkv.com/commands/zrevrange/

```
ZREVRANGE key start stop [WITHSCORES]
```

- Group: Sorted set
- Complexity: O(log(N)+M) where N is the size of the sorted set and M is the number of members returned
- HotKV Cloud: all plans
- On-Premise: no license needed
- Deprecated: use ZRANGE instead

`ZREVRANGE` returns the members of the sorted set at `key` between positions
`start` and `stop`, both included, ordered from the highest score to the
lowest (ties in reverse lexicographic order). Position `0` is the
highest-scored member, and negative positions count from the end. It is the
same as `ZRANGE key start stop REV`; new code can use
[ZRANGE](https://docs.hotkv.com/commands/zrange/index.md).

## Options

| Option | Effect |
| --- | --- |
| `WITHSCORES` | Return each member with its score. Must be written in all upper case or all lower case. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array of members | Same |
| With `WITHSCORES` | Flat array: member, score, ... (scores as bulk strings) | Array of `[member, score]` pairs, the score a double |
| Key does not exist or empty range | Empty array | Same |

Errors:

- `WRONGTYPE` if `key` holds a value that is not a sorted set.
- `ERR value is not an integer or out of range` if `start` or `stop` is not an
  integer.

## Examples

```
127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c"
(integer) 3
127.0.0.1:6379> ZREVRANGE board 0 1
1) "c"
2) "b"
127.0.0.1:6379> ZREVRANGE board 0 -1 WITHSCORES
1) "c"
2) "3"
3) "b"
4) "2"
5) "a"
6) "1"
```

## Compatibility

Same replies as Redis 7.4 and Valkey 8 for valid input. Extra or
unrecognised trailing arguments are ignored, where Redis and Valkey reply
with a syntax error. HotKV also checks the key's type before `start` and
`stop`.

## See also

[ZRANGE](https://docs.hotkv.com/commands/zrange/index.md), [ZREVRANGEBYSCORE](https://docs.hotkv.com/commands/zrevrangebyscore/index.md), [ZREVRANK](https://docs.hotkv.com/commands/zrevrank/index.md)