A TairString is a string that includes a version number. This topic describes the commands that are supported by the TairString data structure.
Overview
Native Redis strings use a key-value pair structure. TairStrings contain keys, values, as well as version numbers to support scenarios including 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 is out 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, see TairString.
Best practices
Prerequisites
- The instance is a performance-enhanced instance or persistent memory-optimized instance of the ApsaraDB for Redis Enhanced Edition (Tair). For more information about performance-enhanced instances and memory-optimized instances, see Performance-enhanced instances and Persistent memory-optimized instances.
- The instance is updated to the latest minor version. For more information, see Update the minor version.
Note If your instance is a cluster instance or read/write splitting instance, the proxy nodes in your instance must also be of the latest minor version to ensure 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.
Precautions
Supported commands
Command | Syntax | Description |
---|---|---|
EXSET | EXSET <key> <value> [EX time] [PX time] [EXAT time] [PXAT time] [NX | XX] [VER version
| ABS version] |
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 time] [PX time] [EXAT time] [EXAT time] [PXAT time] [NX |
XX] [VER version | ABS version] [MIN minval] [MAX maxval] |
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 time] [PX time] [EXAT time] [EXAT time] [PXAT time]
[NX | XX] [VER version | ABS version] [MIN minval] [MAX maxval] |
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 TairString 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. |
EXSET
Item | Description |
---|---|
Syntax | EXSET <key> <value> [EX time] [PX time] [EXAT time] [PXAT time] [NX | XX] [VER version
| ABS version] |
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 time] [PX time] [EXAT time] [EXAT time] [PXAT time] [NX |
XX] [VER version | ABS version] [MIN minval] [MAX maxval] |
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 time] [PX time] [EXAT time] [EXAT time] [PXAT time]
[NX | XX] [VER version | ABS version] [MIN minval] [MAX maxval] |
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 TairString 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 |
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 |
The Sample command:
Sample output:
|