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

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

Introduction

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

Prototype

@Nullable
byte[] getSet(byte[] key, byte[] value);

Source Link

Document

Set value of key and return its old value.

Usage

From source file:com.mauersu.util.redis.DefaultValueOperations.java

public V getAndSet(K key, V newValue) {
    final byte[] rawValue = rawValue(newValue);
    return execute(new ValueDeserializingRedisCallback(key) {

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);//  ww w. j  a v a2  s. com
            return connection.getSet(rawKey, rawValue);
        }
    }, true);
}

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Set value of {@code key} and return its old value.
 * <p>// w w w  .j av  a2 s . c  om
 * See http://redis.io/commands/getset
 * 
 * @param key must not be {@literal null}.
 * @param value value
 * @return byte[]
 */
public static byte[] getSet(byte[] key, byte[] value) {
    return redisTemplate.execute(new RedisCallback<byte[]>() {
        @Override
        public byte[] doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.getSet(key, value);
        }
    });
}

From source file:com.zxy.commons.cache.RedisHelper.java

/**
 * Set value of {@code key} and return its old value.
 * <p>/*from  w  w  w  .  j a  v  a 2  s  . co  m*/
 * See http://redis.io/commands/getset
 * 
 * @param key must not be {@literal null}.
 * @param value value
 * @return byte[]
 */
public byte[] getSet(byte[] key, byte[] value) {
    return redisTemplate.execute(new RedisCallback<byte[]>() {
        @Override
        public byte[] doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.getSet(key, value);
        }
    });
}