TairHash (also known as exHash) is an enhanced hash data structure that allows you to specify expiration times and version numbers for fields. TairHash is flexible and can help simplify business development in most scenarios.
Overview
TairHash and the native Redis HASH support a variety of data interfaces and provide high performance in data processing. However, the native Redis HASH allows you to specify expiration times only for keys. TairHash allows you to specify expiration times for both keys and fields. You can also use TairHash to specify the version numbers of fields. TairHash is flexible and can help simplify business development in most scenarios. TairHash uses 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
TairHash allows you to specify expiration times and version numbers for fields.
TairHash supports efficient and flexible expiration policies for fields. The expiration policies can be active or passive.
TairHash provides a similar syntax to the native Redis HASH.
This module is open-sourced. For more information, see TairHash.
Prerequisites
The instance is of one of the following Tair series types:
Persistent memory-optimized instance whose minor version is 1.2.6 or later
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 or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version. This ensures that all commands can be run as expected.
Precautions
The TairHash data that you want to manage is stored on a Tair instance.
Supported commands
Table 1. TairHash commands
Command | Syntax | Description |
| Adds a field to a TairHash key. If the key does not exist, the key is created. If the field already exists, this command overwrites the current value of the field. | |
| Retrieves the value of a field from a TairHash key. If the key or field does not exist, nil is returned. | |
| 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. | |
| Specifies the absolute expiration time of a field in a TairHash key. Unit: milliseconds. | |
| Specifies the relative expiration time of a field in a TairHash key. Unit: milliseconds. | |
| Specifies the absolute expiration time of a field in a TairHash key. Unit: seconds. | |
| Specifies the relative expiration time of a field in a TairHash key. Unit: seconds. | |
| Queries the TTL of a field in a TairHash key. Unit: milliseconds. | |
| Queries the TTL of a field in a TairHash key. Unit: seconds. | |
| Queries the current version number of a field in a TairHash key. | |
| Specifies the version number of a field in a TairHash key. | |
| Increases the value of a field in a TairHash key by the num value. 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. | |
| Increases the value of a field in a TairHash key by the num value. 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. | |
| Retrieves the value and version number of a field from a TairHash key. If the key or field does not exist, nil is returned. | |
| 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. | |
| Retrieves the values and version numbers of multiple fields from a TairHash key in each query. | |
| 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. | |
| Checks whether a field exists in a TairHash key. | |
| Retrieves the length of a field value from a TairHash key. | |
| Retrieves all fields from a TairHash key. | |
| Retrieves all field values from a TairHash key. | |
| Retrieves all fields and their values from a TairHash key. | |
| Scans a TairHash key. Note This command is supported only for DRAM-based instances. | |
| Scans a TairHash key. Note This command is supported only for persistent memory-optimized instances. | |
| 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. | |
| 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
Parameter | Description |
Syntax |
|
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 already exists, this command overwrites the current value of the field. Note
|
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHGET
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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 expiration times 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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Queries the TTL of a field in a TairHash key. Unit: seconds. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHVER
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Increases the value of a field in a TairHash key by the num value. 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
Parameter | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Increases the value of a field in a TairHash key by the num value. 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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Checks whether a field exists in a TairHash key. |
Parameter |
|
Output |
|
Example | Sample command:
Sample output:
|
EXHSTRLEN
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
Time complexity | O(N) |
Command description | Retrieves all fields from a TairHash key. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHVALS
Parameter | Description |
Syntax |
|
Time complexity | O(N) |
Command description | Retrieves all field values from a TairHash key. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHGETALL
Parameter | Description |
Syntax |
|
Time complexity | O(N) |
Command description | Retrieves all fields and their values from a TairHash key. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|
EXHSCAN
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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
Parameter | Description |
Syntax |
|
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:
|