Skip to main content

Get Compare Exchange Value Operation

Syntax

Method:

public GetCompareExchangeValueOperation(string key)

Returned object:

public class CompareExchangeValue<T>
{
public readonly string Key;
public readonly T Value;
public readonly long Index;
}
ParameterTypeDescription
KeystringThe unique object identifier
ValueTThe existing value that Key has
IndexlongThe version number of the Value that is stored for the specified Key

You can also get compare exchange values through the session cluster transactions at session.Advanced.ClusterTransaction.

This method also exposes methods getting compare exchange lazily.

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;