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

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

Introduction

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

Prototype

@Nullable
Boolean mSetNX(Map<byte[], byte[]> tuple);

Source Link

Document

Set multiple keys to multiple values using key-value pairs provided in tuple only if the provided key does not exist.

Usage

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

public Boolean multiSetIfAbsent(Map<? extends K, ? extends V> m) {
    if (m.isEmpty()) {
        return true;
    }// w  w w  .  j  av a2  s  .c  o  m

    final Map<byte[], byte[]> rawKeys = new LinkedHashMap<byte[], byte[]>(m.size());

    for (Map.Entry<? extends K, ? extends V> entry : m.entrySet()) {
        rawKeys.put(rawKey(entry.getKey()), rawValue(entry.getValue()));
    }

    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.mSetNX(rawKeys);
        }
    }, true);
}

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

/**
 * Set multiple keys to multiple values using key-value pairs provided in {@code tuple} only if the provided key does
 * not exist.//from   w  ww .ja  v a  2  s. c o m
 * <p>
 * See http://redis.io/commands/msetnx
 * 
 * @param tuple tuple
 * @return Boolean
 */
public static Boolean mSetNX(Map<byte[], byte[]> tuple) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.mSetNX(tuple);
        }
    });
}

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

/**
 * Set multiple keys to multiple values using key-value pairs provided in {@code tuple} only if the provided key does
 * not exist.// w  ww.j  a v a2 s.  c  o  m
 * <p>
 * See http://redis.io/commands/msetnx
 * 
 * @param tuple tuple
 * @return Boolean
 */
public Boolean mSetNX(Map<byte[], byte[]> tuple) {
    return redisTemplate.execute(new RedisCallback<Boolean>() {
        @Override
        public Boolean doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.mSetNX(tuple);
        }
    });
}