The check-and-set methods provide a mechanism for updating information only if the client knows the check (CAS) value. This can be used to prevent clients from updating values in the database that may have changed since the client obtained the value. Methods for storing and updating information support a CAS method that allows you to ensure that the client is updating the version of the data that the client retrieved.
The check value is in the form of a 64-bit integer which is updated every time the value is modified, even if the update of the value does not modify the binary data. Attempting to set or update a key/value pair where the CAS value does not match the value stored on the server will fail.
| API Call | object.Cas(storemode, key, value) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | CasResult<bool> (
Cas result of bool
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
Store a value and get a CasResult with the Cas
for that key.
var casResult = client.Cas(StoreMode.Set, "somekey", "somevalue"); logger.Debug("Cas value: " + casResult.Cas);
| API Call | object.Cas(storemode, key, value, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | CasResult<bool> (
Cas result of bool
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Cas() may also be used with a CAS value.
With this overload, the return value is a
CasResult, where success is determined by
examining the CasResult's Result property.
var casv = client.GetWithCas("somekey"); var casResult = client.Cas(StoreMode.Set, "somekey", "somevalue", casv.Cas); if (casResult.Result) { logger.Debug("Cas result was successful"); }
| API Call | object.Cas(storemode, key, value, validfor, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | CasResult<bool> (
Cas result of bool
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Perform a check and set operation, setting a
TimeStamp expiration on the key.
var casv = client.GetWithCas("somekey"); var casResult = client.Cas(StoreMode.Set, "somekey", "somevalue", TimeSpan.FromMinutes(30), casv.Cas); if (casResult.Result) { logger.Debug("Cas result was successful"); }
| API Call | object.Cas(storemode, key, value, expiresat, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | CasResult<bool> (
Cas result of bool
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
DateTime expiresat | Explicit expiry time for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Perform a check and set operation, setting a
DateTime expiration on the key.
var casv = client.GetWithCas("somekey"); var casResult = client.Cas(StoreMode.Set, "somekey", "somevalue", DateTime.Now.AddMinutes(30), casv.Cas); if (casResult.Result) { logger.Debug("Cas result was successful"); }
| API Call | object.ExecuteCas(storemode, key, value) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | IStoreOperationResult (
Store operation result
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
Store a value and get an IStoreOperationResult
return value.
var storeResult = client.ExecuteCas(StoreMode.Set, "somekey", "somevalue"); logger.Debug("Cas value: " + storeResult.Cas);
| API Call | object.ExecuteCas(storemode, key, value, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | IStoreOperationResult (
Store operation result
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
ulong casunique | Unique value used to verify a key/value combination | ||
ExecuteCas() works like
Cas() and may also be used with a CAS
value. With this overload, the return value is an instance of an
IStoreOperationResult.
var getResult = client.ExecutGet("somekey"); var storeResult = client.Cas(StoreMode.Set, "somekey", "somevalue", getResult.Cas); if (storeResult.Result) { logger.Debug("Cas operation was successful"); }
| API Call | object.ExecuteCas(storemode, key, value, validfor, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | IStoreOperationResult (
Store operation result
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
TimeSpan validfor | Expiry time (in seconds) for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Perform a check and set operation, setting a
TimeStamp expiration on the key. Return an
instance of an IStoreOperationResult.
var getResult = client.ExecutGet("somekey"); var storeResult = client.Cas(StoreMode.Set, "somekey", "somevalue", TimeSpan.FromMinutes(30), getResult.Cas); if (storeResult.Result) { logger.Debug("Cas operation was successful"); }
| API Call | object.ExecuteCas(storemode, key, value, expiresat, casunique) | ||
| Asynchronous | no | ||
| Description | Compare and set a value providing the supplied CAS key matches | ||
| Returns | IStoreOperationResult (
Store operation result
) | ||
| Arguments | |||
StoreMode storemode | Storage mode for a given key/value pair | ||
string key | Document ID used to identify the value | ||
object value | Value to be stored | ||
DateTime expiresat | Explicit expiry time for key | ||
ulong casunique | Unique value used to verify a key/value combination | ||
Perform a check and set operation, setting a
DateTime expiration on the key. Return an
instance of an IStoreOperationResult.
var getResult = client.ExecutGet("somekey"); var storeResult = client.Cas(StoreMode.Set, "somekey", "somevalue", DateTime.Now.AddMinutes(30), getResult.Cas); if (storeResult.Result) { logger.Debug("Cas operation was successful"); }