List of usage examples for org.springframework.data.redis.connection RedisConnection select
void select(int dbIndex);
From source file:com.mauersu.util.redis.DefaultListOperations.java
public Long remove(K key, final long count, Object 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.lRem(rawKey, count, rawValue); }//from w ww .j a v a 2 s .c om }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public Long rightPush(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.rPush(rawKey, rawValue); }/*from ww w . j a v a 2 s. co m*/ }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public Long rightPushIfPresent(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.rPushX(rawKey, rawValue); }/*from w w w .ja v a 2 s . c o m*/ }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public V rightPopAndLeftPush(K sourceKey, K destinationKey) { final byte[] rawDestKey = rawKey(destinationKey); return execute(new ValueDeserializingRedisCallback(sourceKey) { protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { connection.select(dbIndex); return connection.rPopLPush(rawSourceKey, rawDestKey); }// w ww .j a va2 s . c om }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public void set(K key, final long index, V value) { final byte[] rawValue = rawValue(value); execute(new ValueDeserializingRedisCallback(key) { protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { connection.select(dbIndex); connection.lSet(rawKey, index, rawValue); return null; }//from ww w .jav a2 s. c o m }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public Long leftPush(K key, V pivot, V value) { final byte[] rawKey = rawKey(key); final byte[] rawPivot = rawValue(pivot); final byte[] rawValue = rawValue(value); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex); return connection.lInsert(rawKey, Position.BEFORE, rawPivot, rawValue); }/*w w w .j a va2 s . c o m*/ }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public V rightPop(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[]> bRPop = connection.bRPop(tm, rawKey); return (CollectionUtils.isEmpty(bRPop) ? null : bRPop.get(1)); }//from www .j a v a 2 s . c o m }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) { final int tm = (int) TimeoutUtils.toSeconds(timeout, unit); final byte[] rawDestKey = rawKey(destinationKey); return execute(new ValueDeserializingRedisCallback(sourceKey) { protected byte[] inRedis(byte[] rawSourceKey, RedisConnection connection) { connection.select(dbIndex); return connection.bRPopLPush(tm, rawSourceKey, rawDestKey); }//from w w w. jav a2 s. co m }, true); }
From source file:com.mauersu.util.redis.DefaultListOperations.java
public Long rightPush(K key, V pivot, V value) { final byte[] rawKey = rawKey(key); final byte[] rawPivot = rawValue(pivot); final byte[] rawValue = rawValue(value); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex); return connection.lInsert(rawKey, Position.AFTER, rawPivot, rawValue); }/*w w w . j a va 2 s. c o m*/ }, true); }
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public Boolean multiSetIfAbsent(Map<? extends K, ? extends V> m) { if (m.isEmpty()) { return true; }/*from w w w. ja va 2s .c om*/ 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); }