ZRANGE

Since 1.1.0Sorted sets

Syntax

ZRANGE key start stop [BYSCORE|BYLEX] [REV] [LIMIT offset count] [WITHSCORES]
  • Flags: readonly
  • ACL categories: @read, @slow, @sortedset
  • Arity: -4

Returns members of the sorted set at key in a range. By default the range is of ranks, from start to stop, both included, lowest score first; negative ranks count from the end.

Options

OptionEffect
BYSCOREstart and stop are scores; ( excludes a bound, -inf and +inf are open ends.
BYLEXstart and stop are lexicographical bounds, as ZRANGEBYLEX takes.
REVHighest first. With BYSCORE or BYLEX, give the higher bound first.
LIMIT offset countWith BYSCORE or BYLEX: skip offset members and return up to count.
WITHSCORESReturn each member with its score.

Reply

  • An array of members; with WITHSCORES, member, score, member, score, and so on.

Examples

> ZADD r 1 a 2 b 3 c 4 d 5 e
(integer) 5
> ZRANGE r -2 -1 WITHSCORES
1) "d"
2) "4"
3) "e"
4) "5"
> ZRANGE r (2 +inf BYSCORE LIMIT 0 2
1) "c"
2) "d"
> ZRANGE r 4 2 BYSCORE REV
1) "d"
2) "c"
3) "b"