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 void put(K key, HK hashKey, HV value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);
    final byte[] rawHashValue = rawHashValue(value);

    execute(new RedisCallback<Object>() {

        public Object doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            connection.hSet(rawKey, rawHashKey, rawHashValue);
            return null;
        }/*from ww  w .j av  a2 s.  c  om*/
    }, true);
}

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

public Set<V> difference(final K key, final Collection<K> otherKeys) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {

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

    return deserializeValues(rawValues);
}

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

public Set<V> intersect(K key, Collection<K> otherKeys) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {

        public Set<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sInter(rawKeys);
        }/*  w w w .j  av a  2 s.c  om*/
    }, true);

    return deserializeValues(rawValues);
}

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

public Long intersectAndStore(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);
            connection.sInterStore(rawDestKey, rawKeys);
            return null;
        }/*  w w w .  j  a va2s .co m*/
    }, true);
}

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

public Set<V> members(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.sMembers(rawKey);
        }//  w  w  w  . ja  va  2 s.  co m
    }, true);

    return deserializeValues(rawValues);
}

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

public Set<V> union(K key, Collection<K> otherKeys) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {

        public Set<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sUnion(rawKeys);
        }/*from w  w  w  .ja v  a  2  s. c  o  m*/
    }, true);

    return deserializeValues(rawValues);
}

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

@SuppressWarnings("unchecked")
public HV get(K key, Object hashKey) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawHashKey = rawHashKey(hashKey);

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

        public byte[] doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.hGet(rawKey, rawHashKey);
        }/*from  ww w.j a  v a 2s  .co  m*/
    }, true);

    return (HV) deserializeHashValue(rawHashValue);
}

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

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

    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sMove(rawKey, rawDestKey, rawValue);
        }//from  w w w .  j  a  v a2  s  .c o  m
    }, true);
}

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

public Set<V> distinctRandomMembers(K key, final long count) {
    if (count < 0) {
        throw new IllegalArgumentException(
                "Negative count not supported. " + "Use randomMembers to allow duplicate elements.");
    }/*from   w  w w . j a  v a  2  s .c om*/
    final byte[] rawKey = rawKey(key);
    Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
        public Set<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return new HashSet<byte[]>(connection.sRandMember(rawKey, count));
        }
    }, true);

    return deserializeValues(rawValues);
}

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

public List<V> randomMembers(K key, final long count) {
    if (count < 0) {
        throw new IllegalArgumentException(
                "Use a positive number for count. " + "This method is already allowing duplicate elements.");
    }//www  . j av  a  2s  .c  o m
    final byte[] rawKey = rawKey(key);
    List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() {
        public List<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.sRandMember(rawKey, -count);
        }
    }, true);

    return deserializeValues(rawValues);
}