A TairString (exString) 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 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
A performance-enhanced or persistent memory-optimized instance of Tair whose minor version is 1.2.3 or later is created. For more information about performance-enhanced instances and persistent memory-optimized instances, see DRAM-based instances and Persistent memory-optimized instances.
Precautions
The TairStrings that you want to manage are stored in the Tair instance.
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 for 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 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 TairString 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.A|B
: 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 for 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 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 TairString key when the current version number of the key matches the specified one. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
|