This topic describes the commands that you can run on ApsaraDB for Redis Enhanced Edition (Tair) instances to enhance the string function. These commands include Compare And Set (CAS) and Compare And Delete (CAD).
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 |
---|---|---|
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.
|
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 |