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

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

Introduction

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

Prototype

@Nullable
Boolean hSetNX(byte[] key, byte[] field, byte[] value);

Source Link

Document

Set the value of a hash field only if field does not exist.

Usage

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

public Boolean putIfAbsent(K key, HK hashKey, HV value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);
    final byte[] rawHashValue = rawHashValue(value);

    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);//  ww  w .  ja  va  2 s .  c om
            return connection.hSetNX(rawKey, rawHashKey, rawHashValue);
        }
    }, true);
}

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

/**
 * Set the {@code value} of a hash {@code field} only if {@code field} does not exist.
 * /*from   ww  w  . j av  a2  s .c  o m*/
 * @see http://redis.io/commands/hsetnx
 * @param key key
 * @param field field
 * @param value value
 * @return Boolean
 */
public static Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.hSetNX(key, field, value);
        }
    });
}

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

/**
 * Set the {@code value} of a hash {@code field} only if {@code field} does not exist.
 * /*  w  w  w.  j  a  v a2  s.com*/
 * @see http://redis.io/commands/hsetnx
 * @param key key
 * @param field field
 * @param value value
 * @return Boolean
 */
public Boolean hSetNX(byte[] key, byte[] field, byte[] value) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.hSetNX(key, field, value);
        }
    });
}