# XREVRANGE

> Return the stream entries with IDs in a range, newest first.

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

```
XREVRANGE key end start [COUNT count]
```

- Group: Stream
- Complexity: O(log N + M), M being the entries returned
- HotKV Cloud: all plans
- On-Premise: no license needed

`XREVRANGE` works like [XRANGE](https://docs.hotkv.com/commands/xrange/index.md) but returns entries in
descending ID order, and takes the bounds in the opposite order: the higher
bound (`end`) first, then the lower bound (`start`).

The bounds accept the same forms as XRANGE: `+`, `-`, a full ID, a bare
millisecond time (as `end` it means the last ID of that millisecond, as
`start` the first), and `(` before an ID to exclude it.

## Options

| Option | Effect |
| --- | --- |
| `COUNT count` | Return at most `count` entries, starting from the newest. |

## Return value

An array of entries, each `[id, [field, value, ...]]`, in the same shape for
RESP2 and RESP3.

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Entries in range | Array of entries, newest first | Array of entries |
| Nothing in range, or no such key | Empty array | Empty array |
| `COUNT` of 0 or less on an existing stream | Nil array | Null |

The error replies are the same as for XRANGE, including `WRONGTYPE`.

## Examples

```
127.0.0.1:6379> XADD log 1700000000000-0 msg a
"1700000000000-0"
127.0.0.1:6379> XADD log 1700000000001-0 msg b
"1700000000001-0"
127.0.0.1:6379> XADD log 1700000000002-0 msg c
"1700000000002-0"
127.0.0.1:6379> XREVRANGE log + - COUNT 2
1) 1) "1700000000002-0"
   2) 1) "msg"
      2) "c"
2) 1) "1700000000001-0"
   2) 1) "msg"
      2) "b"
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[XRANGE](https://docs.hotkv.com/commands/xrange/index.md), [XREAD](https://docs.hotkv.com/commands/xread/index.md), [XADD](https://docs.hotkv.com/commands/xadd/index.md)