Get Compare Exchange Values Operation
-
Use
GetCompareExchangeValuesOperation
to return the saved compare-exchange Values for the specified Keys. -
For an overview of the 'Compare Exchange' feature click: Compare Exchange Overview
-
In this page:
Syntax
Methods:
public GetCompareExchangeValuesOperation(string startWith, int? start = null, int? pageSize = null)
Parameters | Type | Description |
---|---|---|
startWith | string | A common prefix for those keys whose values should be returned |
start | int | The number of items that should be skipped |
pageSize | int | The maximum number of values that will be retrieved |
Returned object:
public class CompareExchangeValue<T>
{
public readonly string Key;
public readonly T Value;
public readonly long Index;
}
Return Value | Description |
---|---|
Dictionary<string, CompareExchangeValue<T>> |
A Dictionary containing 'Key' to 'CompareExchangeValue' associations |
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 - Get Values for Specified Keys
Dictionary<string, CompareExchangeValue<string>> compareExchangeValues
= store.Operations.Send(
new GetCompareExchangeValuesOperation<string>(new[] { "Key-1", "Key-2" }));
Example II - Get Values for Keys with Common Prefix
// Get values for keys that have the common prefix 'users'
// Retrieve maximum 20 entries
Dictionary<string, CompareExchangeValue<User>> compareExchangeValues
= store.Operations.Send(new GetCompareExchangeValuesOperation<User>("users", 0, 20));