The best Memcached CAS command Tutorial In 2024, In this tutorial you can learn Memcached CAS command
Memcached CAS (Check-And-Set or Compare-And-Swap) command is used to execute a "check and set" operation
It is only after the current client last value, the key value corresponding to the case where no other client modified to be able to write values.
Checks are carried out by cas_token parameters, this parameter is a unique 64-bit value Memcach assigned to the existing elements.
The basic syntax CAS command is as follows:
cas key flags exptime bytes unique_cas_token [noreply] value
Parameters are as follows:
To use CAS commands on Memcached, you need to get a token (token) from Memcached service providers through gets command.
Function gets command similar basic get command. The difference between the two commands is that, gets a little more information returned: 64-bit integer values very much like the name / value pairs "version" identifier.
Examples of the following steps:
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: