All Products
Search
Document Center

Tair (Redis® OSS-Compatible):exZset

Last Updated:Aug 19, 2025

TairZset (exZset) enables you to sort items by scores with up to 256 dimensions of the double type. This feature is useful for leaderboards in industries such as gaming, live streaming, music, and e-commerce. It greatly improves data processing efficiency and simplifies client-side implementation because it does not require encoding or decoding.

Introduction to TairZset

The native Redis Sorted Set (also known as Zset) supports sorting by only a single double-precision score. This makes it difficult to implement multi-dimensional sorting. For example, using methods such as IEEE 754 bit-level concatenation is complex, reduces precision, and prevents the use of the EXZINCRBY command.

The TairZset data structure, developed by Alibaba Cloud, simplifies the implementation of multi-dimensional sorting. It has the following advantages over traditional methods:

  • Supports sorting by scores with up to 256 dimensions of the double type. The sorting priority is from left to right.

    For a multi-dimensional score, the leftmost score has the highest priority. For example, with a three-dimensional score such as score1#score2#score3, TairZset first compares score1. If the score1 values are equal, TairZset then compares score2. If the score2 values are also equal, TairZset compares score3. If all score dimensions are identical, the elements are sorted by lexicographic order (ASCII order).

    To make this easier to understand, you can think of the hash symbol (#) as a decimal point (.). For example, the relationship between 0#99, 99#90, and 99#99 can be understood as 0.99 < 99.90 < 99.99. Therefore, 0#99 < 99#90 < 99#99.

  • Supports the EXZINCRBY command. You no longer need to retrieve the current data, increment the value locally, and then write it back to Tair.

  • Provides an API similar to the native Zset API.

  • Provides capabilities for both standard leaderboards and distributed architecture leaderboards .

  • Provides an open-source TairJedis client. You do not need to perform any encoding or decoding. You can also use the open-source implementation as a reference to develop clients in other languages.

Typical scenarios

TairZset is suitable for leaderboard scenarios in industries such as gaming, live streaming, music, and e-commerce. Examples include the following:

  • Live streaming leaderboards: In a streamer competition, streamers are first ranked by their current popularity score. If their popularity scores are the same, they are ranked by the number of likes. If the number of likes is also the same, they are ranked by the total value of gifts received.

  • Medal tables: Participants are ranked based on the number of gold, silver, and bronze medals. They are first sorted by the number of gold medals. If the number of gold medals is the same, they are sorted by the number of silver medals. If the number of silver medals is also the same, they are sorted by the number of bronze medals.

  • Game leaderboards: Players are ranked based on multiple dimensions, such as score, task completion time, and rank level.

This module is open-source. For more information, see TairZset.

Best practices

Prerequisites

The instance must be a Tair memory-optimized instance. If the instance is a memory-optimized instance compatible with Redis 5.0, its minor version must be 1.7.1 or later.

Note

The latest minor version provides more features and higher stability. We recommend that you update the instance to the latest minor version. For more information, see Update the minor version of an instance. If your instance is a cluster instance or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version to ensure that all commands can be run as expected.

Notes

The commands in this topic apply to TairZset data in a Tair instance.

Commands

Command

Syntax

Description

EXZADD

EXZADD key [NX|XX] [CH] [INCR] score member [score member ...]

Stores one or more members with their scores in the TairZset at the specified key.

Note

To implement multi-dimensional sorting, use a hash symbol (#) to separate the scores for each dimension, such as 111#222#121. All members in the key must have the same score format.

EXZINCRBY

EXZINCRBY key increment member

Increments the score of a member in the TairZset at the specified key by the value of increment.

EXZSCORE

EXZSCORE key member

Returns the score of a member in the TairZset at the specified key. If the key or member does not exist, it returns nil.

EXZRANGE

EXZRANGE key min max [WITHSCORES]

Returns the specified range of elements from the TairZset at the specified key.

EXZREVRANGE

EXZREVRANGE key min max [WITHSCORES]

Returns the specified range of elements from the TairZset at the specified key. Elements are ordered from high to low score. Elements with the same score are ordered in reverse lexicographic order.

Note

Other than the reverse sorting order, this command is similar to EXZRANGE.

EXZRANGEBYSCORE

EXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]

Returns all elements in the TairZset at the specified key with a score between min and max (inclusive). Elements are ordered from low to high score. Elements with the same score are ordered by lexicographic order.

EXZREVRANGEBYSCORE

EXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

Returns all elements in the TairZset at the specified key with a score between min and max (inclusive). Unlike the default sorting order, this command returns elements ordered from high to low score. Elements with the same score are ordered in reverse lexicographic order.

Note

Other than the reverse sorting order, this command is similar to EXZRANGEBYSCORE. Note that max comes before min in this command.

EXZRANGEBYLEX

EXZRANGEBYLEX key min max [LIMIT offset count]

When all elements in a TairZset have the same score, this command returns all elements at the specified key that are between the min and max lexicographical range.

EXZREVRANGEBYLEX

EXZREVRANGEBYLEX key max min [LIMIT offset count]

When all elements in a TairZset have the same score, this command returns all elements at the specified key that are between the max and min lexicographical range.

Note

Other than the reverse sorting order, this command is similar to EXZRANGEBYLEX. Note that max comes before min in this command.

EXZREM

EXZREM key member [member ...]

Removes the specified members from the TairZset at the specified key. Non-existent members are ignored.

EXZREMRANGEBYSCORE

EXZREMRANGEBYSCORE key min max

Removes all elements in the TairZset at the specified key with a score between min and max (inclusive).

EXZREMRANGEBYRANK

EXZREMRANGEBYRANK key start stop

Removes all elements in the TairZset at the specified key with a rank between start and stop.

EXZREMRANGEBYLEX

EXZREMRANGEBYLEX key min max

When all elements in a TairZset have the same score, this command removes all elements at the specified key that are between the max and min lexicographical range.

Note

If you run this command and the EXZRANGEBYLEX command with the same min and max parameter values, this command removes the same elements that the EXZRANGEBYLEX command returns.

EXZCARD

EXZCARD key

Returns the cardinality (number of elements) of the TairZset at the specified key.

EXZRANK

EXZRANK key member

Returns the rank of a member in the TairZset at the specified key, with scores ordered from low to high. The rank (or index) is 0-based, so the member with the lowest score has a rank of 0.

EXZREVRANK

EXZREVRANK key member

Returns the rank of a member in the TairZset at the specified key, with scores ordered from high to low. The rank (or index) is 0-based, so the member with the highest score has a rank of 0.

Note

Other than the reverse sorting order, this command is similar to EXZRANK.

EXZCOUNT

EXZCOUNT key min max

Returns the number of elements in the TairZset at the specified key with a score between min and max.

EXZLEXCOUNT

EXZLEXCOUNT key min max

When all elements in a TairZset have the same score, this command returns the number of elements at the specified key that are between the min and max lexicographical range.

EXZRANKBYSCORE

EXZRANKBYSCORE key score

Calculates the rank of a given score in the TairZset at the specified key, with scores ordered from low to high. The rank (or index) is 0-based, so the member with the lowest score has a rank of 0.

Note

If the specified score does not exist, the command returns the prospective rank of that score in the TairZset. If the specified score already exists, Tair ranks the specified score before the existing score by default.

EXZREVRANKBYSCORE

EXZREVRANKBYSCORE key score

Calculates the rank of a given score in the TairZset at the specified key, with scores ordered from high to low. The rank (or index) is 0-based, so the member with the highest score has a rank of 0.

Note

If the specified score does not exist, the command returns the prospective rank of that score in the TairZset. If the specified score already exists, Tair ranks the specified score after the existing score by default.

DEL

DEL key [key ...]

Deletes one or more TairZset keys using the native Redis DEL command.

Note

The following list describes the conventions for the command syntax used in this topic:

  • Uppercase keyword: indicates the command keyword.

  • Italic text: indicates variables.

  • [options]: indicates that the enclosed parameters are optional. Parameters that are not enclosed by brackets must be specified.

  • A|B: indicates that the parameters separated by the vertical bars (|) are mutually exclusive. Only one of the parameters can be specified.

  • ...: indicates that the parameter preceding this symbol can be repeatedly specified.

EXZADD

Category

Description

Syntax

EXZADD key [NX|XX] [CH] [INCR] score member [score member ...]

Time complexity

O(N)

Command description

Stores one or more members with their scores in the TairZset at the specified key. The system performs different actions based on whether the key and member exist:

  • If the specified key or member does not exist, the system creates it and inserts the score.

  • If the specified key and member already exist, the system updates (overwrites) the score.

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

Note

To implement multi-dimensional sorting, use a hash symbol (#) to separate the scores for each dimension, such as 111#222#121. All members in the key must have the same score format.

Options

  • NX: Adds only new elements. Does not update existing elements.

  • XX: Updates only existing elements. Does not add new elements.

  • CH: Normally, this command returns the number of new elements added. This option changes the return value to the total number of elements that changed.

    Note

    Changed elements include new elements and existing elements whose scores were updated. Therefore, if the score of an existing element in the command does not change, it is not counted as a changed element.

  • INCR: When this option is specified, EXZADD behaves like EXZINCRBY. In this mode, you can specify only one score-element pair.

Return value

An integer that indicates the following:

  • If no options are specified, returns the number of elements added to the key (excluding elements whose scores were only updated).

  • If the CH option is specified, returns the number of elements that were changed (added or updated).

  • If the INCR option is specified, returns the new score of the member as a string. If you use multi-dimensional scores, the format is "score1#score2#score3#...", such as 2#0#6.

    Note

    If the operation is aborted (because the command includes the XX or NX option), it returns nil.

Examples

Command example:

EXZADD testkey NX 1#0#3 a 1#0#2 b

Return example:

(integer) 2

EXZINCRBY

Category

Description

Syntax

EXZINCRBY key increment member

Time complexity

O(log(N))

Command description

Increments the score of a member in the TairZset at the specified key by the value of increment. The system performs different actions based on whether the key and member exist:

  • If the specified key or member does not exist, the system creates it and inserts the score.

  • If the specified key and member already exist, the system updates (increments) the score.

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

Note
  • To implement multi-dimensional sorting, use a hash symbol (#) to separate the scores for each dimension, such as 111#222#121. All members in the key must have the same score format.

  • The score value must be a string representation of a numeric value, which can be a double-precision floating-point number. To decrease the score of a member, specify a negative number.

Options

None

Return value

Returns the new score of the member as a string. If you use multi-dimensional scores, the format is "score1#score2#score3#...", such as 2#0#6.

Examples

Command example:

EXZINCRBY testkey 2#2#1 a

Return example:

"3#2#4"

EXZSCORE

Category

Description

Syntax

EXZSCORE key member

Time complexity

O(1)

Command description

Returns the score of a member in the TairZset at the specified key. If the key or member does not exist, it returns nil.

Options

None

Return value

Returns the score of the member as a string. If you use multi-dimensional scores, the format is "score1#score2#score3#...", such as 2#0#6.

Examples

Command example:

EXZSCORE testkey a

Return example:

"3#2#4"

EXZRANGE

Category

Description

Syntax

EXZRANGE key min max [WITHSCORES]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Command description

Returns the specified range of elements from the TairZset at the specified key.

Options

  • min and max are 0-based indexes. The index of the first element is 0, the index of the second element is 1, and so on. You can use these two parameters to specify a closed interval.

    Note
    • If an index is negative, it indicates an offset from the end of the returned elements. For example, -1 represents the last element of the key, and -2 represents the second to last element.

    • To query all elements, set min to 0 and max to -1.

    • If the value of min is greater than the index of the last element in the key or the value of max, an empty list is returned.

  • WITHSCORES: Includes the scores of the elements in the return value. The data format of the returned list is value1, score1, ..., valueN, scoreN. For example:

    1) "b"
    2) "1#0#2"
    3) "a"
    4) "3#2#4"

Return value

Returns a list of elements in the specified range. If you use the WITHSCORES option, the return value includes the scores of the elements.

Examples

Command example:

EXZRANGE testkey 0 -1 WITHSCORES

Example response:

1) "b"
2) "1#0#2"
3) "a"
4) "3#2#4"

EXZREVRANGE

Category

Description

Syntax

EXZREVRANGE key min max [WITHSCORES]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Command description

Returns the specified range of elements from the TairZset at the specified key. Elements are ordered from high to low score. Elements with the same score are ordered in reverse lexicographic order.

Note

Other than the reverse sorting order, this command is similar to EXZRANGE.

Options

  • min and max are 0-based indexes. The index of the first element is 0, the index of the second element is 1, and so on. You can use these two parameters to specify a closed interval.

    Note
    • If an index is negative, it indicates an offset from the end of the returned elements. For example, -1 represents the last element of the key, and -2 represents the second to last element.

    • To query all elements, set min to 0 and max to -1.

    • If the value of min is greater than the index of the last element in the key or the value of max, an empty list is returned.

  • WITHSCORES: Includes the scores of the elements in the return value. The data format of the returned list is value1, score1, ..., valueN, scoreN. For example:

    1) "b"
    2) "1#0#2"
    3) "a"
    4) "3#2#4"

Return value

Returns a list of elements in the specified range. If you use the WITHSCORES option, the return value includes the scores of the elements.

Examples

Command example:

EXZREVRANGE testkey 0 -1 WITHSCORES

Return example:

1) "a"
2) "3#2#4"
3) "b"
4) "1#0#2"

EXZRANGEBYSCORE

Category

Description

Syntax

EXZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Note

When M is a constant (for example, when you use the LIMIT option to always return the top 10 elements), the complexity can be considered O(log(N)).

Command description

Returns all elements in the TairZset at the specified key with a score between min and max (inclusive). Elements are ordered from low to high score. Elements with the same score are ordered by lexicographic order.

Options

  • min and max represent the minimum and maximum scores. If the elements in the key use multi-dimensional scores, use a hash symbol (#) to separate the scores for each dimension.

    Note
    • If you are unsure of the highest and lowest scores of the elements in the key and want to query elements with scores greater than or equal to, or less than or equal to a specific value, set min and max to negative infinity (-inf) and positive infinity (+inf), respectively.

    • The data range is a closed interval by default. To specify an open interval, add a parenthesis before the score range. For example, (1 5 returns elements with scores greater than 1 and less than or equal to 5.

  • WITHSCORES: Includes the scores of the elements in the return value.

  • LIMIT offset count: Specifies the number and interval of the returned results. If count is negative, all elements from the offset are returned.

    Note

    If offset is large, the entire key must be traversed to locate the offset element before elements can be returned. This increases the time complexity.

Return value

Returns a list of elements in the specified score range. If you use the WITHSCORES option, the return value includes the scores of the elements.

Examples

Command example:

EXZRANGEBYSCORE testkey 0#0#0 6#6#6 WITHSCORES

Return example:

1) "b"
2) "1#0#2"
3) "a"
4) "3#2#4"

EXZREVRANGEBYSCORE

Category

Description

Syntax

EXZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Note

When M is a constant (for example, when you use the LIMIT option to always return the top 10 elements), the complexity can be considered O(log(N)).

Command description

Returns all elements in the TairZset at the specified key with a score between min and max (inclusive). Unlike the default sorting order in TairZset, this command returns elements ordered from high to low score. Elements with the same score are ordered in reverse lexicographic order.

Note

Other than the reverse sorting order, this command is similar to EXZRANGEBYSCORE. Note that max comes before min in this command.

Options

  • min and max represent the minimum and maximum scores. If the elements in the key use multi-dimensional scores, use a hash symbol (#) to separate the scores for each dimension.

    Note
    • If you are unsure of the highest and lowest scores of the elements in the key and want to query elements with scores greater than or equal to, or less than or equal to a specific value, set min and max to negative infinity (-inf) and positive infinity (+inf), respectively.

    • The data range is a closed interval by default. To specify an open interval, add a parenthesis before the score range. For example, (1 5 returns elements with scores greater than 1 and less than or equal to 5.

  • WITHSCORES: Includes the scores of the elements in the return value.

  • LIMIT offset count: Specifies the number and interval of the returned results. If count is negative, all elements from the offset are returned.

    Note

    If offset is large, the entire key must be traversed to locate the offset element before elements can be returned. This increases the time complexity.

Return value

Returns a list of elements in the specified score range. If you use the WITHSCORES option, the return value includes the scores of the elements.

Examples

Command example:

EXZREVRANGEBYSCORE testkey 6#6#6 0#0#0 WITHSCORES

Return example:

1) "a"
2) "3#2#4"
3) "b"
4) "1#0#2"

EXZRANGEBYLEX

Category

Description

Syntax

EXZRANGEBYLEX key min max [LIMIT offset count]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Note

When M is a constant (for example, when you use the LIMIT option to return the top 10 elements), the complexity can be considered O(log(N)).

Command description

When all elements in a TairZset have the same score, this command returns elements from the key that are between the min and max lexicographical range. This ensures that elements are sorted by lexicographic order.

Note
  • If the elements in the key have different scores, the returned elements are undefined.

  • The command uses the memcmp() C function to compare the bytes in two element strings one by one. Elements are sorted from low to high based on the comparison result. If two strings share a common substring, the longer string is considered to have a higher value.

Options

  • min and max represent the minimum and maximum member names as strings. You must specify the character range. For example:

    • Open interval: Add a parenthesis before the value, such as (a.

    • Closed interval: Add a square bracket before the value, such as [a.

    Note

    Positive and negative infinity are represented by + and -, respectively.

  • LIMIT offset count: Specifies the number and interval of the returned results. If count is negative, all elements from the offset are returned.

    Note

    If offset is large, the entire key must be traversed to locate the offset element before elements can be returned. This increases the time complexity.

Return value

Returns a list of elements whose names are within the specified range.

Examples

Command example:

EXZRANGEBYLEX zzz [a [b

Return example:

1) "aba"
2) "abc"

EXZREVRANGEBYLEX

Category

Description

Syntax

EXZREVRANGEBYLEX key max min [LIMIT offset count]

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements returned.

Note

When M is a constant (for example, when you use the LIMIT option to always return the top 10 elements), the complexity can be considered O(log(N)).

Command description

When all elements in a TairZset have the same score, this command returns elements from the key that are between the max and min lexicographical range.

Note

Other than the reverse sorting order, this command is similar to EXZRANGEBYLEX. Note that max comes before min in this command.

Options

  • min and max represent the minimum and maximum member names as strings. You must specify the character range. For example:

    • Open interval: Add a parenthesis before the value, such as (a.

    • Closed interval: Add a square bracket before the value, such as [a.

    Note

    Positive and negative infinity are represented by + and -, respectively.

  • LIMIT offset count: Specifies the number and interval of the returned results. If count is negative, all elements from the offset are returned.

    Note

    If offset is large, the entire key must be traversed to locate the offset element before elements can be returned. This increases the time complexity.

Return value

Returns a list of elements whose names are within the specified range.

Examples

Command example:

EXZREVRANGEBYLEX zzz [b [a

Return example:

1) "abc"
2) "aba"

EXZREM

Category

Description

Syntax

EXZREM key member [member ...]

Time complexity

O(M*log(N)), where N is the number of elements in the TairZset and M is the number of elements to be removed.

Command description

Removes the specified members from the TairZset at the specified key. Non-existent members are ignored.

Note

If the specified key exists but its data structure is not a TairZset, an error is returned.

Options

None

Return value

Returns the number of members that were removed from the key, not including non-existent members.

Examples

Command example:

EXZREM testkey a

Return example:

(integer) 1

EXZREMRANGEBYSCORE

Category

Description

Syntax

EXZREMRANGEBYSCORE key min max

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements to be removed.

Command description

Removes all elements in the TairZset at the specified key with a score between min and max (inclusive).

Options

min and max represent the minimum and maximum scores. If the elements in the key use multi-dimensional scores, use a hash symbol (#) to separate the scores for each dimension.

Note
  • If you are unsure of the highest and lowest scores of the elements in the key and want to remove elements with scores greater than or equal to, or less than or equal to a specific value, set min and max to negative infinity (-inf) and positive infinity (+inf), respectively.

  • The data range is a closed interval by default. To specify an open interval, add a parenthesis before the score range. For example, EXZREMRANGEBYSCORE (1 5 deletes elements with scores greater than 1 and less than or equal to 5.

Return value

Returns the number of elements removed.

Examples

Command example:

EXZREMRANGEBYSCORE testkey 3#2#4 6#6#6

Return example:

(integer) 1

EXZREMRANGEBYRANK

Category

Description

Syntax

EXZREMRANGEBYRANK key start stop

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements removed by the operation.

Command description

Removes all elements in the TairZset at the specified key with a rank between start and stop.

Options

start and stop are 0-based indexes, where 0 represents the element with the lowest score. If an index is negative, it represents an offset from the element with the highest score. For example, -1 is the element with the highest score, and -2 is the element with the second-highest score.

Return value

The number of elements removed.

Examples

Command example:

EXZREMRANGEBYRANK testkey 0 1EXZREVRANGEBYSCORE

Return example:

(integer) 1

EXZREMRANGEBYLEX

Category

Description

Syntax

EXZREMRANGEBYLEX key min max

Time complexity

O(log(N)+M), where N is the number of elements in the TairZset and M is the number of elements removed by the operation.

Command description

When all elements in a TairZset have the same score, this command removes elements from the key that are between the max and min lexicographical range. This ensures that elements are sorted by lexicographic order.

Note

If you run this command and the EXZRANGEBYLEX command with the same min and max parameter values, this command removes the same elements that the EXZRANGEBYLEX command returns.

Options

min and max represent the minimum and maximum member names as strings. You must specify the character range. For example:

  • Open interval: Add a parenthesis before the value, such as (a.

  • Closed interval: Add a square bracket before the value, such as [a.

Return value

The number of elements removed.

Examples

Command example:

EXZREMRANGEBYLEX [a [b

Return example:

(integer) 2

EXZCARD

Category

Description

Syntax

EXZCARD key

Time complexity

O(1)

Command description

Returns the cardinality (number of elements) of the TairZset at the specified key.

Options

None

Return value

Returns the number of elements in the key. If the key does not exist, it returns 0.

Examples

Command example:

EXZCARD testkey

Return example:

(integer) 2

EXZRANK

Category

Description

Syntax

EXZRANK key member

Time complexity

O(log(N))

Command description

Returns the rank of a member in the TairZset at the specified key, with scores ordered from low to high. The rank (or index) is 0-based, so the member with the lowest score has a rank of 0.

Options

None

Return value

  • If the specified member exists in the key, returns the rank of the member as an integer.

  • If the key or the member in the key does not exist, returns nil.

Examples

Command example:

EXZRANK testkey b

Return example:

(integer) 0

EXZREVRANK

Category

Description

Syntax

EXZREVRANK key member

Time complexity

O(log(N))

Command description

Returns the rank of a member in the TairZset at the specified key. The results are ordered from high to low score. The rank (or index) is 0-based, so the member with the highest score has a rank of 0.

Note

Other than the reverse sorting order, this command is similar to EXZRANK.

Options

None

Return value

  • If the specified member exists in the key, returns the rank of the member as an integer.

  • If the key or the member in the key does not exist, returns nil.

Examples

Command example:

EXZREVRANK testkey b

Return example:(integer) 1

(integer) 1

EXZCOUNT

Category

Description

Syntax

EXZCOUNT key min max

Time complexity

O(log(N)), where N is the number of elements in the TairZset.

Note

Because the query range is obtained based on element ranks, the amount of work involved in this operation is not proportional to the size of the query range.

Command description

Returns the number of elements in the TairZset at the specified key with a score between min and max.

Options

min and max represent the minimum and maximum scores. If the elements in the key use multi-dimensional scores, use a hash symbol (#) to separate the scores for each dimension.

Note
  • If you are unsure of the highest and lowest scores of the elements in the key and want to query elements with scores greater than or equal to, or less than or equal to a specific value, set min and max to negative infinity and positive infinity, respectively.

  • The data range is a closed interval by default. To specify an open interval, add a parenthesis before the score range. For example, (1 5 returns elements with scores greater than 1 and less than or equal to 5.

Return value

Returns the number of elements (as an integer) within the specified score range.

Examples

Command example:

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

Return example:

(integer) 1

EXZLEXCOUNT

Category

Description

Syntax

EXZLEXCOUNT key min max

Time complexity

O(log(N)), where N is the number of elements in the TairZset.

Note

Because the query range is obtained based on element ranks, the amount of work involved in this operation is not proportional to the size of the query range.

Command description

When all elements in a TairZset have the same score, this command returns the number of elements at the specified key that are between the min and max lexicographical range. This ensures that elements are sorted by lexicographic order.

Note
  • If the elements in the key have different scores, the returned elements are undefined.

  • The command uses the memcmp() C function to compare the bytes in two element strings one by one. Elements are sorted from low to high based on the comparison result. If two strings share a common substring, the longer string is considered to have a higher value.

Options

min and max represent the minimum and maximum member names as strings. You must specify the character range. For example:

  • Open interval: Add a parenthesis before the value, such as (a.

  • Closed interval: Add a square bracket before the value, such as [a.

Return value

Returns the number of elements (as an integer) within the specified score range.

Examples

Command example:

EXZLEXCOUNT zzz [a [b

Return example:

(integer) 2

EXZRANKBYSCORE

Category

Description

Syntax

EXZRANKBYSCORE key score

Time complexity

O(log(N))

Command description

Calculates the rank of a given score in the TairZset at the specified key, with scores ordered from low to high. The rank (or index) is 0-based, so the member with the lowest score has a rank of 0.

Note

If the specified score does not exist, the command returns the prospective rank of that score in the TairZset. If the specified score already exists, Tair ranks the specified score before the existing score by default.

Options

None

Return value

Returns the rank of the specified score in the key.

Examples

Command example:

EXZRANKBYSCORE testkey 2#0#2 

Return example:

(integer) 1

EXZREVRANKBYSCORE

Category

Description

Syntax

EXZREVRANKBYSCORE key score

Time complexity

O(log(N))

Command description

Calculates the rank of a given score in the TairZset at the specified key, with scores ordered from high to low. The rank (or index) is 0-based, so the member with the highest score has a rank of 0.

Note

If the specified score does not exist, the command returns the prospective rank of that score in the TairZset. If the specified score already exists, Tair ranks the specified score after the existing score by default.

Options

None

Return value

Returns the rank of the specified score in the key.

Examples

Command example:

EXZREVRANKBYSCORE testkey 2#0#2 

Return example:

(integer) 1