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

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

Introduction

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

Prototype

void select(int dbIndex);

Source Link

Document

Select the DB with given positive dbIndex .

Usage

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

public void multiSet(Map<? extends K, ? extends V> m) {
    if (m.isEmpty()) {
        return;/*from www  .  ja  v a 2s  .  co 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()));
    }

    execute(new RedisCallback<Object>() {

        public Object doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            connection.mSet(rawKeys);
            return null;
        }
    }, true);
}

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

public List<V> multiGet(Collection<K> keys) {
    if (keys.isEmpty()) {
        return Collections.emptyList();
    }/*w w  w . j a  v  a2s .  com*/

    final byte[][] rawKeys = new byte[keys.size()][];

    int counter = 0;
    for (K hashKey : keys) {
        rawKeys[counter++] = rawKey(hashKey);
    }

    List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() {

        public List<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.mGet(rawKeys);
        }
    }, true);

    return deserializeValues(rawValues);
}

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

public Boolean setIfAbsent(K key, V value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawValue = rawValue(value);

    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
            connection.select(dbIndex);
            return connection.setNX(rawKey, rawValue);
        }/*from  w ww  . j  av a2s  .c om*/
    }, true);
}

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

public Double increment(K key, HK hashKey, final double delta) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);

    return execute(new RedisCallback<Double>() {
        public Double doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hIncrBy(rawKey, rawHashKey, delta);
        }/*from w  w  w  .  j  av a 2s. com*/
    }, true);
}

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

public Long size(K key) {
    final byte[] rawKey = rawKey(key);

    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hLen(rawKey);
        }/*from w ww . j a  v  a2 s .  c o m*/
    }, true);
}

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

public V pop(K key) {
    return execute(new ValueDeserializingRedisCallback(key) {

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sPop(rawKey);
        }/* w  w  w .jav a  2s .c om*/
    }, true);
}

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

public Boolean hasKey(K key, Object hashKey) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);

    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hExists(rawKey, rawHashKey);
        }//from ww  w. ja  v  a 2 s  . co m
    }, true);
}

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

public V randomMember(K key) {

    return execute(new ValueDeserializingRedisCallback(key) {

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sRandMember(rawKey);
        }/*from ww  w .ja v a 2 s .c  o  m*/
    }, true);
}

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

public Long size(K key) {
    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sCard(rawKey);
        }//from  ww w . j a v a2 s  .  co m
    }, true);
}

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

public Long increment(K key, HK hashKey, final long delta) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);

    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hIncrBy(rawKey, rawHashKey, delta);
        }/*  ww w.  j a  v a  2s. co m*/
    }, true);

}