XREVRANGE

Syntax

  1. XREVRANGE key end start [COUNT count]

Time complexity: O(N) with N being the number of elements being returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).

XREVRANGE is almost same as XRANGE. The only difference is it returns the entries in reverse order, and also takes the start-end range in reverse order (as you can notice in the syntax). Reverse order means the range starts with higher IDs and ends with lower IDs.

So for instance, the following command returns all the elements from the higher ID to the lower ID:

  1. XREVRANGE mystream + -

COUNT option limits the number of entries returned by the command.

  1. XREVRANGE mystream + - COUNT 2

Return

Array reply

The return format is exactly same as XRANGE command.

Example

  1. dragonfly> XREVRANGE mystream + -
  2. 1) 1) "1687927770804-0"
  3. 2) 1) "k3"
  4. 2) "v3"
  5. 2) 1) "1687927767585-0"
  6. 2) 1) "k2"
  7. 2) "v2"
  8. 3) 1) "1687927765116-0"
  9. 2) 1) "k"
  10. 2) "v"