XREVRANGE

Syntax

  1. XREVRANGE key end start [COUNT count]

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).

This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, and the command will produce all the element between (or exactly like) the two IDs, starting from the end side.

So for instance, to get all the elements from the higher ID to the lower ID one could use:

  1. XREVRANGE somestream + -

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

  1. XREVRANGE somestream + - COUNT 1

See XRANGE for more detail.

Return

Array reply, specifically:

The command returns the entries with IDs matching the specified range, from the higher ID to the lower ID matching. The returned entries are complete, that means that the ID and all the fields they are composed are returned. Moreover the entries are returned with their fields and values in the exact same order as XADD added them.

Examples

  1. dragonfly> XADD writers * name Virginia surname Woolf
  2. "1676903941132-0"
  3. dragonfly> XADD writers * name Jane surname Austen
  4. "1676903941132-1"
  5. dragonfly> XADD writers * name Toni surname Morrison
  6. "1676903941132-2"
  7. dragonfly> XADD writers * name Agatha surname Christie
  8. "1676903941133-0"
  9. dragonfly> XADD writers * name Ngozi surname Adichie
  10. "1676903941133-1"
  11. dragonfly> XLEN writers
  12. (integer) 5
  13. dragonfly> XREVRANGE writers + - COUNT 1
  14. 1) 1) "1676903941133-1"
  15. 2) 1) "name"
  16. 2) "Ngozi"
  17. 3) "surname"
  18. 4) "Adichie"