TairHash (also known as exHash) is a hash data type that allows you to specify expiration times and version numbers for fields. As a result, TairHash is flexible and can help you simplify business development in most scenarios.
Overview
TairHashes and native Redis hashes support a variety of data interfaces and provide high performance in data processing. However, native Redis hashes allow you to specify expiration times only for keys. TairHashes allow you to specify expiration times for both keys and fields. You can also use TairHashes to specify the version numbers of fields. These improved features of TairHashes add flexibility to TairHash and simplify business development in most scenarios. TairHashes use the efficient active expiration algorithm to check the expiration times of fields and delete expired fields. This process does not increase the database response time.
Main features- The expiration time and version number for each field can be specified.
- The efficient and flexible active and passive expiration strategies for fields are supported.
- TairHashes and native Redis hashes use similar syntax.
This module is open-sourced. For more information, see TairHash.
Prerequisites
- DRAM-based instances
- Persistent memory-optimized instances that run the minor version of 1.2.6 or later.
Precautions
The TairHash data that you want to manage is stored on Tair instances.
Supported commands
Command | Syntax | Description |
---|---|---|
EXHSET | EXHSET key field value [EX time] [EXAT time] [PX time] [PXAT time] [NX | XX] [VER | ABS version] [KEEPTTL] | Adds a field to a TairHash key. If the key does not exist, the key is created. If the field has an existing value, this command overwrites the existing value. |
EXHGET | EXHGET key field | Retrieves the value of a field from a TairHash key. If the key or field does not exist, nil is returned. |
EXHMSET | EXHMSET key field value [field value ...] | Adds multiple fields to a TairHash key. If the key does not exist, the key is created. If these fields already exist in the key, this command overwrites the values of these fields. |
EXHPEXPIREAT | EXHPEXPIREAT key field milliseconds-timestamp [VER | ABS version] | Specifies the absolute expiration time of a field in a TairHash key. Unit: milliseconds. |
EXHPEXPIRE | EXHPEXPIRE key field milliseconds [VER | ABS version] | Specifies the relative expiration time of a field in a TairHash key. Unit: milliseconds. |
EXHEXPIREAT | EXHEXPIREAT key field timestamp [VER | ABS version] | Specifies the absolute expiration time of a field in a TairHash key. Unit: seconds. |
EXHEXPIRE | EXHEXPIRE key field seconds [VER | ABS version] | Specifies the relative expiration time of a field in a TairHash key. Unit: seconds. |
EXHPTTL | EXHPTTL key field | Queries the TTL of a field in a TairHash key. Unit: milliseconds. |
EXHTTL | EXHTTL key field | Queries the expiration time of a field in a TairHash key. Unit: seconds. |
EXHVER | EXHVER key field | Queries the current version number of a field in a TairHash key. |
EXHSETVER | EXHSETVER key field version | Specifies the version number of a field in a TairHash key. |
EXHINCRBY | EXHINCRBY key field num [EX time] [EXAT time] [PX time] [PXAT time] [VER | ABS version] [MIN minval] [MAX maxval] [KEEPTTL] | Increases the value of a field by the num value in a TairHash key. The num value must be an integer. If the key does not exist, the key is created. If the field does not exist, this command adds the field and sets the value of the field to 0 before increasing the value of the field. Note To add a field that does not expire, you can run this command to add the field without specifying an expiration time. |
EXHINCRBYFLOAT | EXHINCRBYFLOAT key field num [EX time] [EXAT time] [PX time] [PXAT time] [VER | ABS version] [MIN minval] [MAX maxval] [KEEPTTL] | Increases the value of a field by the num value in a TairHash key. The num value must be a floating-point number. If the key does not exist, the key is created. If the field does not exist, this command adds the field and sets the value of the field to 0 before increasing the value of the field. Note To add a field that does not expire, you can run this command to add the field without specifying an expiration time. |
EXHGETWITHVER | EXHGETWITHVER key field | Retrieves the value and version number of a field from a TairHash key. If the key or field does not exist, nil is returned. |
EXHMGET | EXHMGET key field [field ...] | Retrieves multiple field values from a TairHash key in each query. If the key does not exist or if the fields do not exist, nil is returned. |
EXHMGETWITHVER | EXHMGETWITHVER key field [field ...] | Retrieves the values and version numbers of multiple fields from a TairHash key in each query. |
EXHLEN | EXHLEN key [NOEXP] | Retrieves the number of fields in a TairHash key. The output may include the number of expired fields that are not deleted because this command does not trigger a passive eviction of or filter out expired fields. If you want to retrieve only the number of fields that have not expired, you can set the NOEXP parameter in your command. |
EXHEXISTS | EXHEXISTS key field | Checks whether a field exists in a TairHash key. |
EXHSTRLEN | EXHSTRLEN key field | Retrieves the length of a field value from a TairHash key. |
EXHKEYS | EXHKEYS key | Retrieves all fields from a specified TairHash key. |
EXHVALS | EXHVALS key | Retrieves all field values from a specified TairHash key. |
EXHGETALL | EXHGETALL key | Retrieves all fields from a TairHash key and their values. |
EXHSCAN | EXHSCAN key op subkey [MATCH pattern] [COUNT count] | Scans a TairHash key. Note This command is supported only for DRAM-based instances. |
EXHSCANUNORDER | EXHSCANUNORDER key cursor [MATCH pattern] [COUNT count] | Scans a TairHash key. Note This command is supported only for persistent memory-optimized instances. |
EXHDEL | EXHDEL key field [field ...] | Deletes a field from a TairHash key. If the key or field does not exist, a value of 0 is returned. If the field is deleted, a value of 1 is returned. |
DEL | DEL <key> [key ...] | Deletes one or more TairHash keys. |
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.
EXHSET
Item | Description |
---|---|
Syntax | EXHSET key field value [EX time] [EXAT time] [PX time] [PXAT time] [NX | XX] [VER | ABS version] [KEEPTTL] |
Time complexity | O(1) |
Command description | Adds a field to a TairHash key. If the key does not exist, the key is created. If the field has an existing value, this command overwrites the existing value. Note
|
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHGET
Item | Description |
---|---|
Syntax | EXHGET key field |
Time complexity | O(1) |
Command description | Retrieves the value of a field from a TairHash key. If the key or field does not exist, nil is returned. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHMSET
Item | Description |
---|---|
Syntax | EXHMSET key field value [field value ...] |
Time complexity | O(N) |
Command description | Adds multiple fields to a TairHash key. If the key does not exist, the key is created. If these fields already exist in the key, this command overwrites the values of these fields. Note After you create a key, you can run the EXHPEXPIREAT, EXHPEXPIRE, EXHEXPIREAT, or EXHEXPIRE command to specify an expiration time for the fields that are added to the key. You can also run the EXPIRE or EXPIREAT command to specify an expiration time for the key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHPEXPIREAT
Item | Description |
---|---|
Syntax | EXHPEXPIREAT key field milliseconds-timestamp [VER | ABS version] |
Time complexity | O(1) |
Command description | Specifies the absolute expiration time of a field in a TairHash key. Unit: milliseconds. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHPEXPIRE
Item | Description |
---|---|
Syntax | EXHPEXPIRE key field milliseconds [VER | ABS version] |
Time complexity | O(1) |
Command description | Specifies the relative expiration time of a field in a TairHash key. Unit: milliseconds. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHEXPIREAT
Item | Description |
---|---|
Syntax | EXHEXPIREAT key field timestamp [VER | ABS version] |
Time complexity | O(1) |
Command description | Specifies the absolute expiration time of a field in a TairHash key. Unit: seconds. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHEXPIRE
Item | Description |
---|---|
Syntax | EXHEXPIRE key field seconds [VER | ABS version] |
Time complexity | O(1) |
Command description | Specifies the relative expiration time of a field in a TairHash key. Unit: seconds. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHPTTL
Item | Description |
---|---|
Syntax | EXHPTTL key field |
Time complexity | O(1) |
Command description | Queries the TTL of a field in a TairHash key. Unit: milliseconds. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHTTL
Item | Description |
---|---|
Syntax | EXHTTL key field |
Time complexity | O(1) |
Command description | Queries the expiration time of a field in a TairHash key. Unit: seconds. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHVER
Item | Description |
---|---|
Syntax | EXHVER key field |
Time complexity | O(1) |
Command description | Queries the current version number of a field in a TairHash key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHSETVER
Item | Description |
---|---|
Syntax | EXHSETVER key field version |
Time complexity | O(1) |
Command description | Specifies the version number of a field in a TairHash key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHINCRBY
Item | Description |
---|---|
Syntax | EXHINCRBY key field num [EX time] [EXAT time] [PX time] [PXAT time] [VER | ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Time complexity | O(1) |
Command description | Increases the value of a field by the num value in a TairHash key. The num value must be an integer. If the key does not exist, the key is created. If the field does not exist, this command adds the field and sets the value of the field to 0 before increasing the value of the field. Note To add a field that does not expire, you can run this command to add the field without specifying an expiration time. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHINCRBYFLOAT
Item | Description |
---|---|
Syntax | EXHINCRBYFLOAT key field num [EX time] [EXAT time] [PX time] [PXAT time] [VER | ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Time complexity | O(1) |
Command description | Increases the value of a field by the num value in a TairHash key. The num value must be a floating-point number. If the key does not exist, the key is created. If the field does not exist, this command adds the field and sets the value of the field to 0 before increasing the value of the field. Note To add a field that does not expire, you can run this command to add the field without specifying an expiration time. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHGETWITHVER
Item | Description |
---|---|
Syntax | EXHGETWITHVER key field |
Time complexity | O(1) |
Command description | Retrieves the value and version number of a field from a TairHash key. If the key or field does not exist, nil is returned. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHMGET
Item | Description |
---|---|
Syntax | EXHMGET key field [field ...] |
Time complexity | O(1) |
Command description | Retrieves multiple field values from a TairHash key in each query. If the key does not exist or if the fields do not exist, nil is returned. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHMGETWITHVER
Item | Description |
---|---|
Syntax | EXHMGETWITHVER key field [field ...] |
Time complexity | O(1) |
Command description | Retrieves the values and version numbers of multiple fields from a TairHash key in each query. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHLEN
Item | Description |
---|---|
Syntax | EXHLEN key [NOEXP] |
Time complexity | The time complexity is O(1) if the NOEXP parameter is not specified and O(N) if the NOEXP parameter is specified. |
Command description | Retrieves the number of fields in a TairHash key. The output may include the number of expired fields that are not deleted because this command does not trigger a passive eviction of or filter out expired fields. If you want to retrieve only the number of fields that have not expired, you can set the NOEXP parameter in your command. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHEXISTS
Item | Description |
---|---|
Syntax | EXHEXISTS key field |
Time complexity | O(1) |
Command description | Checks whether a field exists in a TairHash key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHSTRLEN
Item | Description |
---|---|
Syntax | EXHSTRLEN key field |
Time complexity | O(1) |
Command description | Retrieves the length of a field value from a TairHash key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHKEYS
Item | Description |
---|---|
Syntax | EXHKEYS key |
Time complexity | O(N) |
Command description | Retrieves all fields from a specified TairHash key. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHVALS
Item | Description |
---|---|
Syntax | EXHVALS key |
Time complexity | O(N) |
Command description | Retrieves all field values from a specified TairHash key. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHGETALL
Item | Description |
---|---|
Syntax | EXHGETALL key |
Time complexity | O(N) |
Command description | Retrieves all fields from a TairHash key and their values. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHSCAN
Item | Description |
---|---|
Syntax | EXHSCAN key op subkey [MATCH pattern] [COUNT count] |
Time complexity | The time complexity is O(1) for every call and O(N) for a complete iteration. |
Command description | Scans a TairHash key. Note This command is supported only for DRAM-based instances. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHSCANUNORDER
Item | Description |
---|---|
Syntax | EXHSCANUNORDER key cursor [MATCH pattern] [COUNT count] |
Time complexity | The time complexity is O(1) for every call and O(N) for a complete iteration. |
Command description | Scans a TairHash key. Note This command is supported only for persistent memory-optimized instances. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHDEL
Item | Description |
---|---|
Syntax | EXHDEL key field [field ...] |
Time complexity | O(1) |
Command description | Deletes a field from a TairHash key. If the key or field does not exist, a value of 0 is returned. If the field is deleted, a value of 1 is returned. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|