XREVRANGE

XREVRANGE key end start [COUNT count]
Available since:
Redis Open Source 5.0.0
Time complexity:
O(N) with N being the number of elements returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).
ACL categories:
@read, @stream, @slow,
Compatibility:
Redis Software and Redis Cloud compatibility

This command works like XRANGE, but returns entries in reverse order. Specify the end ID first, then the start ID. XREVRANGE returns the entries between those IDs, inclusive, starting from the end of the range.

So for example, to get all the elements from the higher ID to the lower ID you can use:

XREVRANGE somestream + -

Similarly to get just the last element added into the stream it is enough to send:

XREVRANGE somestream + - COUNT 1

Required arguments

key

The stream key.

end

The end of the ID range, inclusive. Entries are returned in reverse order. Use + for the greatest ID.

start

The start of the ID range, inclusive. Use - for the smallest ID.

Optional arguments

COUNT count

The maximum number of entries to return.

Examples

XADD writers * name Virginia surname Woolf XADD writers * name Jane surname Austen XADD writers * name Toni surname Morrison XADD writers * name Agatha surname Christie XADD writers * name Ngozi surname Adichie XLEN writers XREVRANGE writers + - COUNT 1

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Active-Active
✅ Standard
✅ Active-Active

Return information

Array reply: The command returns the entries with IDs matching the specified range. The returned entries are complete, which means that the ID and all the fields they are composed of are returned. Moreover, the entries are returned with their fields and values in the same order as XADD added them.

History

  • Starting with Redis version 6.2.0: Added exclusive ranges.
RATE THIS PAGE
Back to top ↑