This topic describes TairString, a self-developed data structure that comes with ApsaraDB for Redis Enhanced Edition (Tair). A TairString is a string that contains a version number.
Overview
Native Redis strings use a key-value pair structure. TairStrings contain keys, values, as well as version numbers to support scenarios that include the implementation of optimistic locking. In native Redis strings, the INCRBY and INCRBYFLOAT commands are used to increase or decrease string values. In TairStrings, you can limit the range of the outputs returned by these commands. If an output falls outside of the specified range, an error message is returned.
Main features- A TairString contains a version number.
- TairStrings allow you to limit the range of the INCRBY and INCRBYFLOAT command outputs when you run these commands to increase values.
This module is open-sourced. For more information, visit TairString.
Best practices
Prerequisites
The instance is a performance-enhanced or persistent memory-optimized instance of the ApsaraDB for Redis Enhanced Edition (Tair) whose minor version is 1.2.3 or later. For more information about performance-enhanced instances and persistent memory-optimized instances, see Performance-enhanced instances and Persistent memory-optimized instances. For more information about how to update the minor version, see Update the minor version.Precautions
- The TairStrings that you want to manage are stored in the instance.
Note You can manage native Redis strings and TairStrings in the instance at the same time. However, native Redis strings do not support the commands described in this topic.
- The latest minor version provides more features and higher stability. We recommend
that you update the instance to the latest minor version.
Note 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. This ensures that all commands can be run as expected. For more information about cluster instances and read/write splitting instances, see Cluster master-replica instances and Read/write splitting instances.
Supported commands
Command | Syntax | Description |
---|---|---|
EXSET | EXSET key value [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [KEEPTTL] |
Creates a TairString key if the key does not exist and writes a value to the key. If the key already exists, the command overwrites the value of the key. |
EXGET | EXGET key |
Retrieves the value and version number of a TairString key. |
EXSETVER | EXSETVER key version |
Specifies the version number of a TairString key. |
EXINCRBY | EXINCRBY key num [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Increases or decreases the value of a TairString key. The value of the num parameter must be of the long type. |
EXINCRBYFLOAT | EXINCRBYFLOAT key num [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Increases or decreases the value of a TairString key. The value of the num parameter must be of the double type. |
EXCAS | EXCAS key newvalue version |
Updates the value of the specified key if the current version number of the key matches the specified one. If the numbers do not match, the command returns the original value and version number of the key. |
EXCAD | EXCAD key version |
Deletes a key when the current version number of the key matches the specified one. |
DEL | DEL key [key ...] |
Deletes one or more TairString 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.
EXSET
Item | Description |
---|---|
Syntax | EXSET key value [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [KEEPTTL] |
Time complexity | O(1) |
Command description |
Creates a TairString key if the key does not exist and writes a value to the key. If the key already exists, the command overwrites the value of the key. |
Parameter |
|
Output |
|
Example |
Sample command:
Sample output:
|
EXGET
Item | Description |
---|---|
Syntax | EXGET key |
Time complexity | O(1) |
Command description |
Retrieves the value and version number of a TairString key. |
Parameter |
|
Output |
|
Example |
Sample command:
Sample output:
|
EXSETVER
Item | Description |
---|---|
Syntax | EXSETVER key version |
Time complexity | O(1) |
Command description |
Specifies the version number of a TairString key. |
Parameter |
|
Output |
|
Example |
Sample command:
Sample output:
|
EXINCRBY
Item | Description |
---|---|
Syntax | EXINCRBY key num [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Time complexity | O(1) |
Command description |
Increases or decreases the value of a TairString key. The value of the num parameter must be of the long type. |
Parameter |
|
Output |
|
Example |
The Sample command:
Sample output:
|
EXINCRBYFLOAT
Item | Description |
---|---|
Syntax | EXINCRBYFLOAT key num [EX|PX|EXAT|PXAT time] [NX|XX] [VER|ABS version] [MIN minval] [MAX maxval] [KEEPTTL] |
Time complexity | O(1) |
Command description |
Increases or decreases the value of a TairString key. The value of the num parameter must be of the double type. |
Parameter |
|
Output |
|
Example |
The Sample command:
Sample output:
|
EXCAS
Item | Description |
---|---|
Syntax | EXCAS key newvalue version |
Time complexity | O(1) |
Command description |
Updates the value of the specified key if the current version number of the key matches the specified one. If the numbers do not match, the command returns the original value and version number of the key. |
Parameter |
|
Output |
|
Example |
Run the Sample command:
Sample output:
|
EXCAD
Item | Description |
---|---|
Syntax | EXCAD key version |
Time complexity | O(1) |
Command description |
Deletes a key when the current version number of the key matches the specified one. |
Parameter |
|
Output |
|
Example |
Run the Sample command:
Sample output:
|