All Products
Search
Document Center

Tair (Redis® OSS-Compatible):exZset

Last Updated:Mar 28, 2026

TairZset (exZset) extends Redis sorted sets with multi-dimension scoring — sort members by up to 256 double-precision floating-point scores, with priority from left to right.

Overview

Redis sorted sets support only a single score per member, which makes multi-dimension ranking difficult. Common workarounds (combining scores with IEEE 754 encoding or string concatenation) introduce precision loss, complex encoding/decoding logic, and the inability to atomically increment individual score dimensions.

TairZset solves this with a native multi-dimension data structure:

  • Up to 256 score dimensions per member, formatted as score1#score2#...#scoreN

  • Left-to-right priority: when comparing two members, the first dimension is compared first; if equal, the second dimension is compared, and so on

  • Atomic increments: EXZINCRBY increments a specific dimension without read-modify-write cycles

  • API compatibility: commands mirror native sorted set commands, requiring no encoding or decoding logic in your client

  • Regular and distributed leaderboards: supports both single-node and distributed leaderboard architectures

  • Open source TairJedis client: available at TairJedis SDK; use the open source code as a reference to implement clients for other languages

The module is open source at TairZset on GitHub.

Use cases

Multi-dimension scoring makes TairZset a natural fit for any leaderboard where a single metric is not enough:

  • Live streaming leaderboards: rank streamers first by popularity, then by likes, then by gift amount — popularity#likes#gift_amount

  • Medal standings: rank competitors by gold medals, then silver, then bronze — gold#silver#bronze

  • Game leaderboards: rank players by score, then by task completion time, then by player rank — score#completion_time#player_rank

How multi-dimension comparison works

TairZset compares scores dimension by dimension, left to right. Consider a two-dimension score score1#score2:

  • 0#99 vs 99#90 vs 99#99: since 0 < 99, the result is 0#99 < 99#90 < 99#99

  • Think of # like a decimal point: 0.99 < 99.90 < 99.99

If all dimensions are equal, TairZset sorts by member name in ASCII order.

Prerequisites

Before you begin, ensure that you have:

Update to the latest minor version for the most features and highest stability. See Update the minor version of an instance. For cluster instances or read/write splitting instances, also update the proxy nodes to ensure all commands run as expected.

Usage notes

  • All TairZset commands operate on TairZset data in Tair instances. Running these commands on a key that holds a different data type returns an error.

  • Score format consistency: all members in the same key must use the same number of score dimensions. Mixing 1#2#3 and 1#2 in the same key causes an error.

  • Increment format: the increment in EXZINCRBY must match the score dimension format of the target member. To increment only one dimension of a three-dimension score, specify all three dimensions (e.g., EXZINCRBY key 0#1#0 member).

  • +inf and -inf are valid score values in all score-range commands.

Quick start

The following example builds a two-dimension live streaming leaderboard: rank by popularity first, then by likes.

# Add streamers with initial scores (popularity#likes)
EXZADD leaderboard 1000#500 alice 800#900 bob 1000#300 carol

# Atomically increment alice's likes without a read-modify-write cycle
EXZINCRBY leaderboard 0#100 alice

# Get the full leaderboard, highest score first
EXZREVRANGE leaderboard 0 -1 WITHSCORES
# 1) "alice"
# 2) "1000#600"
# 3) "carol"
# 4) "1000#300"
# 5) "bob"
# 6) "800#900"

# Get alice's rank (highest = rank 0)
EXZREVRANK leaderboard alice
# (integer) 0

Commands

The following table lists all TairZset commands. Use the native Redis DEL command to delete TairZset keys.

CommandSyntaxComplexityDescription
EXZADDEXZADD key [NX|XX] [CH] [INCR] score member [score member ...]O(M\*log(N))Add or update members with scores
EXZINCRBYEXZINCRBY key increment memberO(log(N))Increment a member's score
EXZSCOREEXZSCORE key memberO(1)Get a member's score
EXZRANGEEXZRANGE key min max [WITHSCORES]O(log(N)+M)Return members by index range, low to high
EXZREVRANGEEXZREVRANGE key min max [WITHSCORES]O(log(N)+M)Return members by index range, high to low
EXZRANGEBYSCOREEXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]O(log(N)+M)Return members by score range, low to high
EXZREVRANGEBYSCOREEXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]O(log(N)+M)Return members by score range, high to low
EXZRANGEBYLEXEXZRANGEBYLEX key min max [LIMIT offset count]O(log(N)+M)Return members by lexicographic range
EXZREVRANGEBYLEXEXZREVRANGEBYLEX key max min [LIMIT offset count]O(log(N)+M)Return members by lexicographic range, reversed
EXZREMEXZREM key member [member ...]O(M\*log(N))Remove members
EXZREMRANGEBYSCOREEXZREMRANGEBYSCORE key min maxO(log(N)+M)Remove members by score range
EXZREMRANGEBYRANKEXZREMRANGEBYRANK key start stopO(log(N)+M)Remove members by rank range
EXZREMRANGEBYLEXEXZREMRANGEBYLEX key min maxO(log(N)+M)Remove members by lexicographic range
EXZCARDEXZCARD keyO(1)Return the number of members
EXZRANKEXZRANK key memberO(log(N))Return a member's rank, low to high
EXZREVRANKEXZREVRANK key memberO(log(N))Return a member's rank, high to low
EXZCOUNTEXZCOUNT key min maxO(log(N))Count members within a score range
EXZLEXCOUNTEXZLEXCOUNT key min maxO(log(N))Count members within a lexicographic range
EXZRANKBYSCOREEXZRANKBYSCORE key scoreO(log(N))Return the rank of a score, low to high
EXZREVRANKBYSCOREEXZREVRANKBYSCORE key scoreO(log(N))Return the rank of a score, high to low
DELDEL key [key ...]Delete one or more TairZset keys

Syntax conventions used in this topic:

  • UPPERCASE KEYWORD: command keyword

  • _italic_: variable

  • [option]: optional parameter

  • A|B: mutually exclusive options (choose one)

  • ...: the preceding parameter can be repeated

EXZADD

CategoryDetails
SyntaxEXZADD key [NX|XX] [CH] [INCR] score member [score member ...]
ComplexityO(M\*log(N)), where N is the number of members in the key and M is the number of members added or updated
DescriptionAdd members with scores to a TairZset key, or update scores for existing members.

Behavior:

  • If the key does not exist, it is created.

  • If a member does not exist, it is added with the given score.

  • If a member already exists, its score is overwritten (unless NX is specified).

  • Each score is a string representation of a double-precision floating-point number. +inf and -inf are valid values.

To use multi-dimension scoring, separate each dimension with #, for example 111#222#121. All members in the key must use the same number of dimensions.

Options:

OptionDescription
NXAdd new members only; skip existing members
XXUpdate existing members only; skip new members
CHChange the return value from the count of newly added members to the count of all changed members (added or score-updated)
INCRTreat the score as an increment, making EXZADD behave like EXZINCRBY. Only one score-member pair is allowed in this mode.

Return value:

  • Without options: the number of newly added members (members with only a score update are not counted)

  • With CH: the number of members added or whose score changed

  • With INCR: the member's new score as a string (e.g., "2#0#6"); returns nil if the operation is skipped due to NX or XX

Example:

EXZADD testkey NX 1#0#3 a 1#0#2 b
(integer) 2

EXZINCRBY

CategoryDetails
SyntaxEXZINCRBY key increment member
ComplexityO(log(N))
DescriptionIncrement a member's score in a TairZset key.

Behavior:

  • If the key or member does not exist, both are created with the score set to increment.

  • If the member exists, its score is incremented by increment.

  • Each score dimension is a double-precision floating-point number. +inf and -inf are valid values.

  • To decrement a score, pass a negative increment.

For multi-dimension scores, increment must use the same format as the member's score. For example, to increment only the second dimension of a three-dimension score, use 0#1#0.

Return value: The member's new score as a string. For multi-dimension scores, the format is "score1#score2#..." (e.g., "2#0#6").

Example:

EXZINCRBY testkey 2#2#1 a
"3#2#4"

EXZSCORE

CategoryDetails
SyntaxEXZSCORE key member
ComplexityO(1)
DescriptionReturn the score of a member in a TairZset key. Returns nil if the key or member does not exist.

Return value: The member's score as a string. For multi-dimension scores, the format is "score1#score2#..." (e.g., "3#2#4").

Example:

EXZSCORE testkey a
"3#2#4"

EXZRANGE

CategoryDetails
SyntaxEXZRANGE key min max [WITHSCORES]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned
DescriptionReturn members within an index range, sorted by score from low to high.

Options:

OptionDescription
min, maxZero-based index values. -1 is the last member, -2 is the second-to-last, and so on. To return all members, use 0 and -1. Returns an empty list if min exceeds the last index or is greater than max.
WITHSCORESInclude scores in the response. The format alternates member and score: member1, score1, member2, score2, ...

Return value: A list of members within the specified range, with scores if WITHSCORES is specified.

Example:

EXZRANGE testkey 0 -1 WITHSCORES
1) "b"
2) "1#0#2"
3) "a"
4) "3#2#4"

EXZREVRANGE

CategoryDetails
SyntaxEXZREVRANGE key min max [WITHSCORES]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned
DescriptionReturn members within an index range, sorted by score from high to low. Members with the same score are sorted in reverse lexicographic order. Same as EXZRANGE except for sort direction.

Options:

OptionDescription
min, maxZero-based index values. -1 is the member with the lowest score, -2 is the second-lowest, and so on. To return all members, use 0 and -1.
WITHSCORESInclude scores in the response.

Return value: A list of members within the specified range, with scores if WITHSCORES is specified.

Example:

EXZREVRANGE testkey 0 -1 WITHSCORES
1) "a"
2) "3#2#4"
3) "b"
4) "1#0#2"

EXZRANGEBYSCORE

CategoryDetails
SyntaxEXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned. When M is constant (e.g., using LIMIT to always return the first 10 members), complexity is O(log(N)).
DescriptionReturn all members with scores between min and max, sorted from low to high. Members with the same score are sorted in lexicographic order.

Options:

OptionDescription
min, maxMinimum and maximum scores. For multi-dimension scores, use # as a separator. Use -inf and +inf when the score boundaries are unknown. By default, the range is a closed interval (min <= score <= max). Prefix a value with ( for an open interval — for example, (1 5 returns members with scores greater than 1 and at most 5.
WITHSCORESInclude scores in the response.
LIMIT offset countLimit the result to count members starting from offset. If count is negative, all members from offset onwards are returned. A large offset increases time complexity because TairZset must traverse the key to reach it.

Return value: A list of members within the score range, with scores if WITHSCORES is specified.

Example:

EXZRANGEBYSCORE testkey 0#0#0 6#6#6 WITHSCORES
1) "b"
2) "1#0#2"
3) "a"
4) "3#2#4"

EXZREVRANGEBYSCORE

CategoryDetails
SyntaxEXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned. When M is constant (e.g., using LIMIT to always return the first 10 members), complexity is O(log(N)).
DescriptionReturn all members with scores between min and max, sorted from high to low. Members with the same score are sorted in reverse lexicographic order. Similar to EXZRANGEBYSCORE, but in reverse order. Note that max comes before min in the syntax.

Options:

OptionDescription
max, minMaximum and minimum scores (note the reversed argument order). For multi-dimension scores, use # as a separator. Use -inf and +inf when the score boundaries are unknown. Prefix a value with ( for an open interval.
WITHSCORESInclude scores in the response.
LIMIT offset countLimit the result to count members starting from offset. A large offset increases time complexity.

Return value: A list of members within the score range, with scores if WITHSCORES is specified.

Example:

EXZREVRANGEBYSCORE testkey 6#6#6 0#0#0 WITHSCORES
1) "a"
2) "3#2#4"
3) "b"
4) "1#0#2"

EXZRANGEBYLEX

CategoryDetails
SyntaxEXZRANGEBYLEX key min max [LIMIT offset count]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned. When M is constant, complexity is O(log(N)).
DescriptionReturn members whose names fall between min and max in lexicographic order. All members in the key must have the same score for results to be predictable.
If members have different scores, the returned set is undefined. Lexicographic comparison uses the C memcmp() function, comparing bytes one at a time. If two strings share a common prefix, the longer string ranks higher.

Options:

OptionDescription
min, maxMember name boundaries. Prefix with [ for a closed interval (e.g., [a) or ( for an open interval (e.g., (a). Use - for negative infinity (the smallest string) and + for positive infinity (the largest string).
LIMIT offset countLimit the result to count members starting from offset. A large offset increases time complexity.

Return value: A list of members within the lexicographic range.

Example:

EXZRANGEBYLEX zzz [a [b
1) "aba"
2) "abc"

EXZREVRANGEBYLEX

CategoryDetails
SyntaxEXZREVRANGEBYLEX key max min [LIMIT offset count]
ComplexityO(log(N)+M), where N is the number of members and M is the number returned. When M is constant, complexity is O(log(N)).
DescriptionReturn members in the lexicographic range between max and min, in reverse order. Same as EXZRANGEBYLEX but reversed. Note that max comes before min in the syntax.

Options:

OptionDescription
max, minMember name boundaries (note the reversed argument order). Prefix with [ for a closed interval or ( for an open interval. Use - and + for negative and positive infinity.
LIMIT offset countLimit the result to count members starting from offset. A large offset increases time complexity.

Return value: A list of members within the lexicographic range, in reverse order.

Example:

EXZREVRANGEBYLEX zzz [b [a
1) "abc"
2) "aba"

EXZREM

CategoryDetails
SyntaxEXZREM key member [member ...]
ComplexityO(M\*log(N)), where N is the number of members and M is the number of members to remove
DescriptionRemove the specified members from a TairZset key. Non-existent members are silently ignored. Returns an error if the key exists but holds a different data type.

Return value: The number of members removed (not counting non-existent members).

Example:

EXZREM testkey a
(integer) 1

EXZREMRANGEBYSCORE

CategoryDetails
SyntaxEXZREMRANGEBYSCORE key min max
ComplexityO(log(N)+M), where N is the number of members and M is the number removed
DescriptionRemove all members with scores between min and max, inclusive.

Options:

OptionDescription
min, maxScore boundaries. For multi-dimension scores, use # as a separator. Use -inf and +inf when the boundaries are unknown. Prefix with ( for an open interval — for example, EXZREMRANGEBYSCORE key (1 5 removes members with scores greater than 1 and at most 5.

Return value: The number of members removed.

Example:

EXZREMRANGEBYSCORE testkey 3#2#4 6#6#6
(integer) 1

EXZREMRANGEBYRANK

CategoryDetails
SyntaxEXZREMRANGEBYRANK key start stop
ComplexityO(log(N)+M), where N is the number of members and M is the number removed
DescriptionRemove all members with ranks between start and stop.

Options:

OptionDescription
start, stopZero-based rank values, where 0 is the member with the lowest score. Negative values count from the highest score: -1 is the highest-scoring member, -2 is the second-highest, and so on.

Return value: The number of members removed.

Example:

EXZREMRANGEBYRANK testkey 0 1
(integer) 1

EXZREMRANGEBYLEX

CategoryDetails
SyntaxEXZREMRANGEBYLEX key min max
ComplexityO(log(N)+M), where N is the number of members and M is the number removed
DescriptionRemove members whose names fall between min and max in lexicographic order. All members must have the same score for results to be predictable. Removes the same members that EXZRANGEBYLEX with identical min and max values would return.

Options:

OptionDescription
min, maxMember name boundaries. Prefix with [ for a closed interval or ( for an open interval.

Return value: The number of members removed.

Example:

EXZREMRANGEBYLEX testkey [a [b
(integer) 2

EXZCARD

CategoryDetails
SyntaxEXZCARD key
ComplexityO(1)
DescriptionReturn the number of members in a TairZset key. Returns 0 if the key does not exist.

Return value: The number of members (integer).

Example:

EXZCARD testkey
(integer) 2

EXZRANK

CategoryDetails
SyntaxEXZRANK key member
ComplexityO(log(N))
DescriptionReturn the rank of a member, with rank 0 assigned to the member with the lowest score (ascending order).

Return value:

  • The member's rank (integer) if the member exists

  • nil if the key or member does not exist

Example:

EXZRANK testkey b
(integer) 0

EXZREVRANK

CategoryDetails
SyntaxEXZREVRANK key member
ComplexityO(log(N))
DescriptionReturn the rank of a member, with rank 0 assigned to the member with the highest score (descending order). Same as EXZRANK but in reverse order.

Return value:

  • The member's rank (integer) if the member exists

  • nil if the key or member does not exist

Example:

EXZREVRANK testkey b
(integer) 1

EXZCOUNT

CategoryDetails
SyntaxEXZCOUNT key min max
ComplexityO(log(N)), where N is the number of members. The work is proportional to the number of elements traversed at the index level, not the size of the score range.
DescriptionReturn the number of members with scores between min and max.

Options:

OptionDescription
min, maxScore boundaries. For multi-dimension scores, use # as a separator. Use -inf and +inf for unbounded queries. Prefix with ( for an open interval — for example, (1 5 counts members with scores greater than 1 and at most 5.

Return value: The number of members within the score range (integer).

Example:

EXZCOUNT testkey (1#0#2 6#6#6
(integer) 1

EXZLEXCOUNT

CategoryDetails
SyntaxEXZLEXCOUNT key min max
ComplexityO(log(N)), where N is the number of members. The work is proportional to the number of elements traversed at the index level.
DescriptionReturn the number of members with names between min and max in lexicographic order. All members must have the same score for results to be predictable.
If members have different scores, the result is undefined. Lexicographic comparison uses the C memcmp() function. If two strings share a common prefix, the longer string ranks higher.

Options:

OptionDescription
min, maxMember name boundaries. Prefix with [ for a closed interval or ( for an open interval.

Return value: The number of members within the lexicographic range (integer).

Example:

EXZLEXCOUNT zzz [a [b
(integer) 2

EXZRANKBYSCORE

CategoryDetails
SyntaxEXZRANKBYSCORE key score
ComplexityO(log(N))
DescriptionReturn the rank a given score would occupy in the key, sorted from low to high (rank 0 = lowest score). If the score does not exist, returns its estimated rank. If the score already exists, the rank is calculated as if the new score were inserted before the existing one.

Return value: The rank of the specified score (integer).

Example:

EXZRANKBYSCORE testkey 2#0#2
(integer) 1

EXZREVRANKBYSCORE

CategoryDetails
SyntaxEXZREVRANKBYSCORE key score
ComplexityO(log(N))
DescriptionReturn the rank a given score would occupy in the key, sorted from high to low (rank 0 = highest score). If the score does not exist, returns its estimated rank. If the score already exists, the rank is calculated as if the new score were inserted after the existing one.

Return value: The rank of the specified score (integer).

Example:

EXZREVRANKBYSCORE testkey 2#0#2
(integer) 1

What's next