Example usage for org.springframework.data.redis.connection RedisConnection get

List of usage examples for org.springframework.data.redis.connection RedisConnection get

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisConnection get.

Prototype

@Nullable
byte[] get(byte[] key);

Source Link

Document

Get the value of key .

Usage

From source file:org.springframework.data.redis.cache.RedisCache.java

public ValueWrapper putIfAbsent(Object key, final Object value) {

    final byte[] keyBytes = computeKey(key);
    final byte[] valueBytes = convertToBytesIfNecessary(template.getValueSerializer(), value);

    return toWrapper(template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {

            waitForLock(connection);//from  w w  w . jav  a2 s  .  c  o m

            Object resultValue = value;
            boolean valueWasSet = connection.setNX(keyBytes, valueBytes);
            if (valueWasSet) {
                connection.zAdd(setName, 0, keyBytes);
                if (expiration > 0) {
                    connection.expire(keyBytes, expiration);
                    // update the expiration of the set of keys as well
                    connection.expire(setName, expiration);
                }
            } else {
                resultValue = deserializeIfNecessary(template.getValueSerializer(), connection.get(keyBytes));
            }

            return resultValue;
        }
    }, true));
}