| API Call | cas key flags expiry value_length casunique | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | binary-string (
Binary object
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
flags | Flags for storage options. Flags are ignored by the server byt preserved for use by the client. | ||
expiry | Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). | ||
value_length | Length of value to be stored | ||
casunique | Unique value used to verify a key/value combination | ||
| API Call | cas key flags expiry value_length casunique noreply | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | binary-string (
Binary object
) | ||
| Arguments | |||
string key | Document ID used to identify the value | ||
flags | Flags for storage options. Flags are ignored by the server byt preserved for use by the client. | ||
expiry | Expiry time for key. Values larger than 30*24*60*60 seconds (30 days) are interpreted as absolute times (from the epoch). | ||
value_length | Length of value to be stored | ||
casunique | Unique value used to verify a key/value combination | ||
noreply | Indicates server should not confirm operation | ||
The cas command performs a compare and swap
operation providing that the supplied casunique
value matches the corresponding casunique value
returned by the server when performing a get or
gets operation.
The compare and swap acts as a check to ensure that a client does
only updates a key/value pair if the information matches what the
client already knows. In deployments where you are using multiple
clients this can be used to ensure that multiple clients do not
overwrite existing key/value pairs that may have already been
modified by a different client. Using cas is a
more efficient method of supporting this operation than performing
multiple get and set operations before updating each key/value
pair.
To use cas you must make use of the
casunique value returned as the final argument
of a get/gets operation. For
example:
gets memVALUE mem 0 11 54 memoryboard END
In the above example, the casunique value for
the key mem is 54. To change
the value of the mem key using
cas, this value must be quoted and matched. For
example: