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

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

Introduction

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

Prototype

@Nullable
Boolean renameNX(byte[] sourceKey, byte[] targetKey);

Source Link

Document

Rename key sourceKey to targetKey only if targetKey does not exist.

Usage

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

/**
 * Rename key {@code oleName} to {@code newName} only if {@code newName} does not exist.
 * <p>/*from   w  w  w .  ja v a  2 s . c o  m*/
 * See http://redis.io/commands/renamenx
 * 
 * @param oldName oldName
 * @param newName newName
 * @return Boolean
 */
public static Boolean renameNX(byte[] oldName, byte[] newName) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.renameNX(oldName, newName);
        }
    });
}

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

/**
 * Rename key {@code oleName} to {@code newName} only if {@code newName} does not exist.
 * <p>//from w  w w  .j  ava  2s .  c  o m
 * See http://redis.io/commands/renamenx
 * 
 * @param oldName oldName
 * @param newName newName
 * @return Boolean
 */
public Boolean renameNX(byte[] oldName, byte[] newName) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.renameNX(oldName, newName);
        }
    });
}