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

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

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

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

public List<V> range(K key, final long start, final long end) {
    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<List<V>>() {
        public List<V> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return deserializeValues(connection.lRange(rawKey, start, end));
        }/*  ww  w  .j  a  v a  2  s.co m*/
    }, true);
}

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

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

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);
            return connection.rPop(rawKey);
        }/*from   ww  w . j av  a2 s. co  m*/
    }, true);
}

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

public Long leftPushAll(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.lPush(rawKey, rawValues);
        }/*from  ww  w  . j a v  a  2s  . c om*/
    }, true);
}

From source file:com.mauersu.util.redis.DefaultListOperations.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.lLen(rawKey);
        }//  w ww  . jav a  2 s  . c o m
    }, true);
}

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

public Long rightPushAll(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.rPush(rawKey, rawValues);
        }/*from w w w.  j  a v a 2  s .co  m*/
    }, true);
}

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

public void trim(K key, final long start, final long end) {
    execute(new ValueDeserializingRedisCallback(key) {

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);
            connection.lTrim(rawKey, start, end);
            return null;
        }/* ww  w  .  java2 s. c  o m*/
    }, true);
}

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

public V leftPop(K key, long timeout, TimeUnit unit) {
    final int tm = (int) TimeoutUtils.toSeconds(timeout, unit);
    return execute(new ValueDeserializingRedisCallback(key) {

        protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
            connection.select(dbIndex);
            List<byte[]> lPop = connection.bLPop(tm, rawKey);
            return (CollectionUtils.isEmpty(lPop) ? null : lPop.get(1));
        }//from  w ww . java 2s.co m
    }, true);
}

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

public Long leftPush(K key, V value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawValue = rawValue(value);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.lPush(rawKey, rawValue);
        }/*from   www . j  av  a2 s . c o  m*/
    }, true);
}

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

public Long leftPushIfPresent(K key, V value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawValue = rawValue(value);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.lPushX(rawKey, rawValue);
        }// w ww .j a va 2 s .com
    }, true);
}