This topic describes new commands supported by Tair instances that can be used to improve the string functionality. The commands include CAS and CAD commands.
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
Supported commands
Command | Syntax | Description |
---|---|---|
CAS | CAS key oldvalue newvalue | Changes the existing value of a specified key if the existing value matches a specified one. Otherwise, the existing value remains unchanged. Note This command applies only to Redis strings. To change TairString values, run the EXCAS command. |
CAD | CAD key value | Deletes a specified key if the existing value of the key matches a specified one. Otherwise, the key is not deleted. Note This command applies only to Redis strings. To delete TairString keys, run the EXCAD command. |
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.
CAS
Item | Description |
---|---|
Syntax | CAS key oldvalue newvalue |
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. Note This command applies only to Redis strings. To change TairString values, run the EXCAS command. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
If you run the |
CAD
Item | Description |
---|---|
Syntax | CAD key value |
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. Note This command applies only to Redis strings. To delete TairString keys, run the EXCAD command. |
Parameter |
|
Output |
|
Example | The Sample command:
Sample output:
After this command is run, the foo key is deleted. Then, if you run the |