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#...#scoreNLeft-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:
EXZINCRBYincrements a specific dimension without read-modify-write cyclesAPI 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_amountMedal standings: rank competitors by gold medals, then silver, then bronze —
gold#silver#bronzeGame 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#99vs99#90vs99#99: since0 < 99, the result is0#99 < 99#90 < 99#99Think 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:
A Tair memory-optimized instance
For memory-optimized instances compatible with Redis 5.0: minor version 1.7.1 or later
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#3and1#2in the same key causes an error.Increment format: the
incrementinEXZINCRBYmust 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).+infand-infare 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.
| Command | Syntax | Complexity | Description |
|---|---|---|---|
| EXZADD | EXZADD key [NX|XX] [CH] [INCR] score member [score member ...] | O(M\*log(N)) | Add or update members with scores |
| EXZINCRBY | EXZINCRBY key increment member | O(log(N)) | Increment a member's score |
| EXZSCORE | EXZSCORE key member | O(1) | Get a member's score |
| EXZRANGE | EXZRANGE key min max [WITHSCORES] | O(log(N)+M) | Return members by index range, low to high |
| EXZREVRANGE | EXZREVRANGE key min max [WITHSCORES] | O(log(N)+M) | Return members by index range, high to low |
| EXZRANGEBYSCORE | EXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] | O(log(N)+M) | Return members by score range, low to high |
| EXZREVRANGEBYSCORE | EXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] | O(log(N)+M) | Return members by score range, high to low |
| EXZRANGEBYLEX | EXZRANGEBYLEX key min max [LIMIT offset count] | O(log(N)+M) | Return members by lexicographic range |
| EXZREVRANGEBYLEX | EXZREVRANGEBYLEX key max min [LIMIT offset count] | O(log(N)+M) | Return members by lexicographic range, reversed |
| EXZREM | EXZREM key member [member ...] | O(M\*log(N)) | Remove members |
| EXZREMRANGEBYSCORE | EXZREMRANGEBYSCORE key min max | O(log(N)+M) | Remove members by score range |
| EXZREMRANGEBYRANK | EXZREMRANGEBYRANK key start stop | O(log(N)+M) | Remove members by rank range |
| EXZREMRANGEBYLEX | EXZREMRANGEBYLEX key min max | O(log(N)+M) | Remove members by lexicographic range |
| EXZCARD | EXZCARD key | O(1) | Return the number of members |
| EXZRANK | EXZRANK key member | O(log(N)) | Return a member's rank, low to high |
| EXZREVRANK | EXZREVRANK key member | O(log(N)) | Return a member's rank, high to low |
| EXZCOUNT | EXZCOUNT key min max | O(log(N)) | Count members within a score range |
| EXZLEXCOUNT | EXZLEXCOUNT key min max | O(log(N)) | Count members within a lexicographic range |
| EXZRANKBYSCORE | EXZRANKBYSCORE key score | O(log(N)) | Return the rank of a score, low to high |
| EXZREVRANKBYSCORE | EXZREVRANKBYSCORE key score | O(log(N)) | Return the rank of a score, high to low |
| DEL | DEL key [key ...] | — | Delete one or more TairZset keys |
Syntax conventions used in this topic:
UPPERCASE KEYWORD: command keyword_italic_: variable[option]: optional parameterA|B: mutually exclusive options (choose one)...: the preceding parameter can be repeated
EXZADD
| Category | Details |
|---|---|
| Syntax | EXZADD key [NX|XX] [CH] [INCR] score member [score member ...] |
| Complexity | O(M\*log(N)), where N is the number of members in the key and M is the number of members added or updated |
| Description | Add 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
NXis specified).Each score is a string representation of a double-precision floating-point number.
+infand-infare valid values.
To use multi-dimension scoring, separate each dimension with#, for example111#222#121. All members in the key must use the same number of dimensions.
Options:
| Option | Description |
|---|---|
NX | Add new members only; skip existing members |
XX | Update existing members only; skip new members |
CH | Change the return value from the count of newly added members to the count of all changed members (added or score-updated) |
INCR | Treat 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 changedWith
INCR: the member's new score as a string (e.g.,"2#0#6"); returnsnilif the operation is skipped due toNXorXX
Example:
EXZADD testkey NX 1#0#3 a 1#0#2 b
(integer) 2EXZINCRBY
| Category | Details |
|---|---|
| Syntax | EXZINCRBY key increment member |
| Complexity | O(log(N)) |
| Description | Increment 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.
+infand-infare valid values.To decrement a score, pass a negative
increment.
For multi-dimension scores,incrementmust use the same format as the member's score. For example, to increment only the second dimension of a three-dimension score, use0#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
| Category | Details |
|---|---|
| Syntax | EXZSCORE key member |
| Complexity | O(1) |
| Description | Return 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
| Category | Details |
|---|---|
| Syntax | EXZRANGE key min max [WITHSCORES] |
| Complexity | O(log(N)+M), where N is the number of members and M is the number returned |
| Description | Return members within an index range, sorted by score from low to high. |
Options:
| Option | Description |
|---|---|
min, max | Zero-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. |
WITHSCORES | Include 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
| Category | Details |
|---|---|
| Syntax | EXZREVRANGE key min max [WITHSCORES] |
| Complexity | O(log(N)+M), where N is the number of members and M is the number returned |
| Description | Return 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:
| Option | Description |
|---|---|
min, max | Zero-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. |
WITHSCORES | Include 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
| Category | Details |
|---|---|
| Syntax | EXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] |
| Complexity | O(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)). |
| Description | Return all members with scores between min and max, sorted from low to high. Members with the same score are sorted in lexicographic order. |
Options:
| Option | Description |
|---|---|
min, max | Minimum 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. |
WITHSCORES | Include scores in the response. |
LIMIT offset count | Limit 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
| Category | Details |
|---|---|
| Syntax | EXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] |
| Complexity | O(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)). |
| Description | Return 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:
| Option | Description |
|---|---|
max, min | Maximum 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. |
WITHSCORES | Include scores in the response. |
LIMIT offset count | Limit 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
| Category | Details |
|---|---|
| Syntax | EXZRANGEBYLEX key min max [LIMIT offset count] |
| Complexity | O(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)). |
| Description | Return 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:
| Option | Description |
|---|---|
min, max | Member 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 count | Limit 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
| Category | Details |
|---|---|
| Syntax | EXZREVRANGEBYLEX key max min [LIMIT offset count] |
| Complexity | O(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)). |
| Description | Return 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:
| Option | Description |
|---|---|
max, min | Member 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 count | Limit 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
| Category | Details |
|---|---|
| Syntax | EXZREM key member [member ...] |
| Complexity | O(M\*log(N)), where N is the number of members and M is the number of members to remove |
| Description | Remove 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) 1EXZREMRANGEBYSCORE
| Category | Details |
|---|---|
| Syntax | EXZREMRANGEBYSCORE key min max |
| Complexity | O(log(N)+M), where N is the number of members and M is the number removed |
| Description | Remove all members with scores between min and max, inclusive. |
Options:
| Option | Description |
|---|---|
min, max | Score 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) 1EXZREMRANGEBYRANK
| Category | Details |
|---|---|
| Syntax | EXZREMRANGEBYRANK key start stop |
| Complexity | O(log(N)+M), where N is the number of members and M is the number removed |
| Description | Remove all members with ranks between start and stop. |
Options:
| Option | Description |
|---|---|
start, stop | Zero-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) 1EXZREMRANGEBYLEX
| Category | Details |
|---|---|
| Syntax | EXZREMRANGEBYLEX key min max |
| Complexity | O(log(N)+M), where N is the number of members and M is the number removed |
| Description | Remove 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:
| Option | Description |
|---|---|
min, max | Member 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) 2EXZCARD
| Category | Details |
|---|---|
| Syntax | EXZCARD key |
| Complexity | O(1) |
| Description | Return 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) 2EXZRANK
| Category | Details |
|---|---|
| Syntax | EXZRANK key member |
| Complexity | O(log(N)) |
| Description | Return 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
nilif the key or member does not exist
Example:
EXZRANK testkey b
(integer) 0EXZREVRANK
| Category | Details |
|---|---|
| Syntax | EXZREVRANK key member |
| Complexity | O(log(N)) |
| Description | Return 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
nilif the key or member does not exist
Example:
EXZREVRANK testkey b
(integer) 1EXZCOUNT
| Category | Details |
|---|---|
| Syntax | EXZCOUNT key min max |
| Complexity | O(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. |
| Description | Return the number of members with scores between min and max. |
Options:
| Option | Description |
|---|---|
min, max | Score 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) 1EXZLEXCOUNT
| Category | Details |
|---|---|
| Syntax | EXZLEXCOUNT key min max |
| Complexity | O(log(N)), where N is the number of members. The work is proportional to the number of elements traversed at the index level. |
| Description | Return 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:
| Option | Description |
|---|---|
min, max | Member 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) 2EXZRANKBYSCORE
| Category | Details |
|---|---|
| Syntax | EXZRANKBYSCORE key score |
| Complexity | O(log(N)) |
| Description | Return 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) 1EXZREVRANKBYSCORE
| Category | Details |
|---|---|
| Syntax | EXZREVRANKBYSCORE key score |
| Complexity | O(log(N)) |
| Description | Return 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