Skip to main content

Method Signature

Parameters

string
required
The key of the sorted set
number | string
required
The minimum range value:
  • By index: 0-based index (use negative for reverse indexing, e.g., -1 for last element)
  • By score: number, (number (exclusive), -inf, or +inf
  • By lex: [member (inclusive), (member (exclusive), - (minimum), or + (maximum)
number | string
required
The maximum range value (same format as min)
ZRangeCommandOptions
Options to control the range query behavior

ZRangeCommandOptions

boolean
Query by score range instead of index. Mutually exclusive with byLex.
boolean
Query by lexicographical range instead of index. All members must have the same score. Mutually exclusive with byScore.
boolean
Reverse the ordering, so elements are returned from highest to lowest score
boolean
Return scores along with members. The result will be a flat array alternating between members and scores.
number
Skip this many elements before returning results. Must be used together with count.
number
Return at most this many elements. Must be used together with offset.

Response

TData
An array of members in the specified range.When withScores is true, returns a flat array alternating between member and score: [member1, score1, member2, score2, ...]

Examples

Get range by index

Get all members

Get range with scores

Get members by score range

Get members by score range (exclusive)

Get members with score infinity bounds

Get members by lexicographical range

Use limit with offset and count

  • ZADD - Add members to a sorted set
  • ZRANK - Get the rank of a member
  • ZSCORE - Get the score of a member
  • ZCARD - Get the number of members