Skip to main content

Compare Exchange: How to Get Compare Exchange Values

Syntax

Methods:

public GetCompareExchangeValuesOperation(string[] keys)
public GetCompareExchangeValuesOperation(string startWith, int? start = null, int? pageSize = null)
ParametersTypeDescription
keysstring[]List of keys to get
startWithstringA common prefix for those keys whose values should be returned
startintThe number of items that should be skipped
pageSizeintThe 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 ValueDescription
Dictionary<string, CompareExchangeValue<T>>A Dictionary containing 'Key' to 'CompareExchangeValue' associations

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));