see on GitHub

Compare Exchange: How to Get Compare Exchange Value



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

Session Interface and Lazy Get

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;