May 17, 2021 Memcached
The Check-And-Set or Compare-And-Swap command is used to perform a "check and set" operation
It is only able to write values if the key's corresponding value has not been modified by other clients after the current client's last value.
The check cas_token a unique 64-bit value assigned by Memcach to an existing element.
The basic syntax of the CAS command is as follows:
cas key flags exptime bytes unique_cas_token [noreply] value
The parameters are described below:
To use CAS commands on Memcached, you need to obtain a token (token) from the Memcached service provider through the gets command.
The gets command functions like a basic get command. T he difference between the two commands is that gets returns slightly more information: the 64-bit integer value is very much like the "version" identifier of a name/value pair.
The example steps are as follows:
cas tp 0 900 9 ERROR <− 缺少 token cas tp 0 900 9 2 memcached NOT_FOUND <− 键 tp 不存在 set tp 0 900 9 memcached STORED gets tp VALUE tp 0 9 1 memcached END cas tp 0 900 5 1 redis STORED get tp VALUE tp 0 5 redis END
If the data is added successfully, the output:
STORED
Output information description: