TairHash is a hash data structure that allows expiration times and version numbers to be specified for fields. This makes TairHash more flexible and simplifies 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 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 the specified 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 To add a field that does not expire, you can run this command to add the field without
specifying an expiration time.
|
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 TairHash key. This command filters out expired fields but does not delete them so that the response time of this command does not increase. |
EXHVALS | EXHVALS key |
Retrieves the values of all fields from a TairHash key. This command filters out expired fields but does not delete them so that the response time of this command does not increase. |
EXHGETALL | EXHGETALL key |
Retrieves all fields from a TairHash key and their values. This command filters out expired fields but does not delete these fields so that the response time of this command does not increase. |
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
: the command keyword.Italic
: Words in italic indicate variable information that you supply.[options]
: optional parameters. Parameters that are not included in brackets are required.AB
: specifies that these parameters are mutually exclusive. Select one of two or more parameters....
: specifies to repeat the preceding content.
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 the specified 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 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 |
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. |
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 TairHash key. This command filters out expired fields but does not delete them so that the response time of this command does not increase. |
Parameter |
|
Output |
|
Example |
The Sample command:
Sample output:
|
EXHVALS
Item | Description |
---|---|
Syntax | EXHVALS key |
Time complexity | O(N) |
Command description |
Retrieves the values of all fields from a TairHash key. This command filters out expired fields but does not delete them so that the response time of this command does not increase. |
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. This command filters out expired fields but does not delete these fields so that the response time of this command does not increase. |
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.
This command filters out expired fields but does not delete them so that the response
time of this command is not increased.
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.
This command filters out expired fields but does not delete them so that the response
time of this command is not increased.
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:
|