This topic describes new commands supported by Tair instances that can be used to enhance string functionality. The commands include CAS and CAD commands.
Prerequisites
The instance is a Tair DRAM-based or persistent memory-optimized instance whose minor version is 1.2.3 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 instance or read/write splitting instance, we recommend that you update the proxy nodes in the instance to the latest minor version to ensure that all commands can be run as expected.
Usage notes
In this topic, the strings that you want to manage are native Redis strings.
You can manage Redis strings and TairStrings on a Tair instance. However, CAS and CAD commands are applicable only to Redis strings.
Supported commands
Table 1. Commands that enhance string functionality
Command | Syntax | Description |
| Changes the existing value of a specified key if the existing value matches a specified one. Otherwise, the existing value remains unchanged. This command applies only to Redis strings. To change TairString values, run the EXCAS command. | |
| Deletes a specified key if the existing value of the key matches a specified one. Otherwise, the key is not deleted. This command applies only to Redis strings. To delete TairString keys, run the EXCAD command. |
The following list describes the conventions for the command syntax used in this topic:
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.
CAS
Item | Description |
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Changes the existing value of a specified key if the existing value matches a specified one. Otherwise, the existing value remains unchanged. This command applies only to Redis strings. To change TairString values, run the EXCAS command. |
Parameter |
|
Output |
|
Example | Run the Sample command:
Sample output:
If you run the |
CAD
Item | Description |
Item | Description |
Syntax |
|
Time complexity | O(1) |
Command description | Deletes a specified key if the existing value of the key matches a specified one. Otherwise, the key is not deleted. This command applies only to Redis strings. To delete TairString keys, run the EXCAD command. |
Parameter |
|
Output |
|
Example | Run the Sample command:
Sample output:
After this command is run, the foo key is deleted. Then, if you run the |