List of usage examples for org.springframework.data.redis.core RedisCallback RedisCallback
RedisCallback
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Long count(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex);/*from ww w . j av a 2 s . c o m*/ return connection.zCount(rawKey, min, max); } }, true); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Set {@code value} for {@code key}.//from w ww . ja v a2 s . c o m * <p> * See http://redis.io/commands/set * * @param key must not be {@literal null}. * @param value must not be {@literal null}. */ public void set(byte[] key, byte[] value) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { redis.set(key, value); return null; } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
@Override public Long zCard(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex);//from www . jav a2 s . c om return connection.zCard(rawKey); } }, true); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Set {@code value} for {@code key}.//from ww w .j av a 2 s.c o m * <p> * See http://redis.io/commands/set * * @param <T> value class type * @param key must not be {@literal null}. * @param value must not be {@literal null}. */ public <T> void set4Json(byte[] key, T value) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { byte[] jsonValue = JsonUtils.toJson(value).getBytes(); redis.set(key, jsonValue); return null; } }); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values * depending on {@code option}.//from w w w . j a va 2 s.co m * <p> * See http://redis.io/commands/set * * @param key must not be {@literal null}. * @param value must not be {@literal null}. * @param expiration can be {@literal null}. Defaulted to {@link Expiration#persistent()}. * @param option can be {@literal null}. Defaulted to {@link SetOption#UPSERT}. * @since 1.7 */ public static void set(byte[] key, byte[] value, Expiration expiration, SetOption option) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { redis.set(key, value, expiration, option); return null; } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.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);//from ww w .j av a2 s . c o m return connection.zUnionStore(rawDestKey, rawKeys); } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Set {@code value} for {@code key}, only if {@code key} does not exist. * <p>// ww w . ja v a2 s . c o m * See http://redis.io/commands/setnx * * @param key must not be {@literal null}. * @param value must not be {@literal null}. * @return Boolean */ public static Boolean setNX(byte[] key, byte[] value) { return redisTemplate.execute(new RedisCallback<Boolean>() { @Override public Boolean doInRedis(RedisConnection redis) throws DataAccessException { return redis.setNX(key, value); } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
@Override public Cursor<TypedTuple<V>> scan(K key, final ScanOptions options) { final byte[] rawKey = rawKey(key); Cursor<Tuple> cursor = execute(new RedisCallback<Cursor<Tuple>>() { @Override/*from w w w . java 2s .com*/ public Cursor<Tuple> doInRedis(RedisConnection connection) throws DataAccessException { connection.select(dbIndex); return connection.zScan(rawKey, options); } }, true); return new ConvertingCursor<Tuple, TypedTuple<V>>(cursor, new Converter<Tuple, TypedTuple<V>>() { @Override public TypedTuple<V> convert(Tuple source) { return deserializeTuple(source); } }); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Set the {@code value} and expiration in {@code seconds} for {@code key}. * <p>/*from w w w .java 2s. co m*/ * See http://redis.io/commands/setex * * @param key must not be {@literal null}. * @param seconds exprise time * @param value must not be {@literal null}. */ public static void setEx(byte[] key, long seconds, byte[] value) { redisTemplate.execute(new RedisCallback<Void>() { @Override public Void doInRedis(RedisConnection redis) throws DataAccessException { redis.setEx(key, seconds, value); return null; } }); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Set {@code value} for {@code key}, only if {@code key} does not exist. * <p>//from ww w. j a v a 2s .c o m * See http://redis.io/commands/setnx * * @param key must not be {@literal null}. * @param value must not be {@literal null}. * @return Boolean */ public Boolean setNX(byte[] key, byte[] value) { return redisTemplate.execute(new RedisCallback<Boolean>() { @Override public Boolean doInRedis(RedisConnection redis) throws DataAccessException { return redis.setNX(key, value); } }); }