You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
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

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;