Compare Exchange: How to Delete Compare Exchange Value
-
Use
DeleteCompareExchangeValueOperation
to delete a Key and its Value. -
The Key and its Value are deleted only if the index in the request matches the current index stored in the server for the specified key.
-
For an overview of the 'Compare Exchange' feature click: Compare Exchange Overview
-
In this page:
Syntax
Method:
public DeleteCompareExchangeValueOperation(string key, long index)
Parameters | ||
---|---|---|
key | string | The key to be deleted |
index | long | The version number of the value to be deleted |
Returned object:
public class CompareExchangeResult<T>
{
public bool Successful;
public T Value;
public long Index;
}
Return Value | |||
---|---|---|---|
Successful | bool | * True if the delete operation was successfully completed * True if key doesn't exist * False if the delete operation failed |
|
Value | T |
* The value that was deleted upon a successful delete * 'null' if key doesn't exist * The currently existing value on the server if delete operation failed |
|
Index | long | * The next available version number upon success * The next available version number if key doesn't exist * The currently existing index on the server if the delete operation failed |
Example
// First, get existing value
CompareExchangeValue<User> readResult =
store.Operations.Send(
new GetCompareExchangeValueOperation<User>("AdminUser"));
// Delete the key - use the index received from the 'Get' operation
CompareExchangeResult<User> deleteResult
= store.Operations.Send(
new DeleteCompareExchangeValueOperation<User>("AdminUser", readResult.Index));
// The delete result is successful only if the index has not changed between the read and delete operations
bool deleteResultSuccessful = deleteResult.Successful;