Compare Exchange: How to Get Compare Exchange Value
-
Use
GetCompareExchangeValueOperation
to return the saved compare-exchange Value for the specified Key. -
For an overview of the 'Compare Exchange' feature click: Compare Exchange Overview
-
In this page:
Syntax
Method:
public GetCompareExchangeValueOperation(string key)
Returned object:
public class CompareExchangeValue<T>
{
public readonly string Key;
public readonly T Value;
public readonly long Index;
}
Key | string | The unique object identifier |
Value | T |
The existing value that Key has |
Index | long | The version number of the Value that is stored for the specified Key |
Example I - Value is 'long'
CompareExchangeValue<long> readResult =
store.Operations.Send(new GetCompareExchangeValueOperation<long>("NextClientId"));
long value = readResult.Value;
Example II - Value is a custom object
CompareExchangeValue<User> readResult =
store.Operations.Send(new GetCompareExchangeValueOperation<User>("AdminUser"));
User admin = readResult.Value;