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.DefaultHashOperations.java

public Set<HK> keys(K key) {
    final byte[] rawKey = rawKey(key);

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

        public Set<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hKeys(rawKey);
        }//from  w ww.j a  va 2s .c o  m
    }, true);

    return deserializeHashKeys(rawValues);
}

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);
            return connection.hSetNX(rawKey, rawHashKey, rawHashValue);
        }/*  ww w. j  a  v a 2  s . c  om*/
    }, true);
}

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

public List<HV> values(K key) {
    final byte[] rawKey = rawKey(key);

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

        public List<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hVals(rawKey);
        }/*  w ww . j a  va  2  s  .c om*/
    }, true);

    return deserializeHashValues(rawValues);
}

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

public void delete(K key, Object... hashKeys) {
    final byte[] rawKey = rawKey(key);
    final byte[][] rawHashKeys = rawHashKeys(hashKeys);

    execute(new RedisCallback<Object>() {

        public Object doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            connection.hDel(rawKey, rawHashKeys);
            return null;
        }/*w  ww.  j ava2 s  . c  o  m*/
    }, true);
}

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

public Map<HK, HV> entries(K key) {
    final byte[] rawKey = rawKey(key);

    Map<byte[], byte[]> entries = execute(new RedisCallback<Map<byte[], byte[]>>() {

        public Map<byte[], byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hGetAll(rawKey);
        }/*  w w w .j  av  a2  s  .  c o  m*/
    }, true);

    return deserializeHashMap(entries);
}

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

public Long add(K key, V... values) {
    final byte[] rawKey = rawKey(key);
    final byte[][] rawValues = rawValues(values);
    return execute(new RedisCallback<Long>() {

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

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

public Long differenceAndStore(final K key, final Collection<K> otherKeys, K destKey) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    final byte[] rawDestKey = rawKey(destKey);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sDiffStore(rawDestKey, rawKeys);
        }/*from ww  w.  j a va 2  s  .co  m*/
    }, true);
}

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

public Boolean isMember(K key, Object o) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawValue = rawValue(o);
    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sIsMember(rawKey, rawValue);
        }/*from www  .j a  va  2 s  .  c  o  m*/
    }, true);
}

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

public Long remove(K key, Object... values) {
    final byte[] rawKey = rawKey(key);
    final byte[][] rawValues = rawValues(values);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sRem(rawKey, rawValues);
        }/*  ww w  .j  a  v  a2 s  . c om*/
    }, true);
}

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

public Long unionAndStore(K key, Collection<K> otherKeys, K destKey) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    final byte[] rawDestKey = rawKey(destKey);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sUnionStore(rawDestKey, rawKeys);
        }//  w w  w. j av a 2  s.  c om
    }, true);
}