Get Compare Exchange Values Operation



Syntax

Methods:

GetCompareExchangeValuesOperation(Class<T> clazz, String[] keys);

GetCompareExchangeValuesOperation(Class<T> clazz, String startWith)
GetCompareExchangeValuesOperation(Class<T> clazz, String startWith, Integer start)
GetCompareExchangeValuesOperation(Class<T> clazz, String startWith, Integer start, Integer pageSize)
Parameters Type Description
keys String[] List of keys to get
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> {
    private String key;
    private long index;
    private T value;

    public CompareExchangeValue(String key, long index, T value) {
        this.key = key;
        this.index = index;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public long getIndex() {
        return index;
    }

    public void setIndex(long index) {
        this.index = index;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }
}
Return Value Description
Map<String, CompareExchangeValue<T>> A map containing 'Key' to 'CompareExchangeValue' associations

Example I - Get Values for Specified Keys

Map<String, CompareExchangeValue<String>> compareExchangeValues
    = store.operations().send(
        new GetCompareExchangeValuesOperation<>(String.class, new String[]{"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
Map<String, CompareExchangeValue<User>> compareExchangeValues
    = store.operations().send(
        new GetCompareExchangeValuesOperation<>(User.class, "users", 0, 20));