List of usage examples for org.springframework.data.redis.core RedisCallback RedisCallback
RedisCallback
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() { public Set<Tuple> doInRedis(RedisConnection connection) { connection.select(dbIndex);//from ww w .j av a 2s . c o m return connection.zRangeByScoreWithScores(rawKey, min, max); } }, true); return deserializeTupleValues(rawValues); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Get the value of {@code key}./*from ww w . j a v a 2 s . c om*/ * <p> * See http://redis.io/commands/get * * @param <T> return object type * @param key must not be {@literal null}. * @param clazz clazz * @return value */ public <T> T getObject4Json(byte[] key, Class<T> clazz) { return redisTemplate.execute(new RedisCallback<T>() { @Override public T doInRedis(RedisConnection redis) throws DataAccessException { // return callback.transfer(redis.get(key)); byte[] value = redis.get(key); if (value == null) { return null; } return JsonUtils.toObject(new String(value), clazz); } }); }
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public void set(K key, final V value, final long offset) { final byte[] rawKey = rawKey(key); final byte[] rawValue = rawValue(value); execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) { connection.select(dbIndex);//from w ww. j ava2 s .co m connection.setRange(rawKey, rawValue, offset); return null; } }, true); }
From source file:com.mauersu.util.redis.DefaultSetOperations.java
public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex);//from w ww .j a v a2 s.c o m return connection.sCard(rawKey); } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}./*from w ww.jav a 2 s. c o m*/ * <p> * See http://redis.io/commands/get * * @param <T> return object type * @param key must not be {@literal null}. * @param clazz clazz * @return value */ public static <T> List<T> getList4Json(byte[] key, Class<T> clazz) { return redisTemplate.execute(new RedisCallback<List<T>>() { @Override public List<T> doInRedis(RedisConnection redis) throws DataAccessException { // return callback.transfer(redis.get(key)); byte[] value = redis.get(key); if (value == null) { return null; } return JsonUtils.toList(new String(value), clazz); } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max, final long offset, final long count) { final byte[] rawKey = rawKey(key); Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() { public Set<Tuple> doInRedis(RedisConnection connection) { connection.select(dbIndex);//from w ww . j av a 2 s . c o m return connection.zRangeByScoreWithScores(rawKey, min, max, offset, count); } }, true); return deserializeTupleValues(rawValues); }
From source file:com.mauersu.util.redis.DefaultHashOperations.java
@Override public Cursor<Entry<HK, HV>> scan(K key, final ScanOptions options) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback<Cursor<Map.Entry<HK, HV>>>() { @Override/*from w ww . ja va2 s .co m*/ public Cursor<Entry<HK, HV>> doInRedis(RedisConnection connection) throws DataAccessException { return new ConvertingCursor<Map.Entry<byte[], byte[]>, Map.Entry<HK, HV>>( connection.hScan(rawKey, options), new Converter<Map.Entry<byte[], byte[]>, Map.Entry<HK, HV>>() { @Override public Entry<HK, HV> convert(final Entry<byte[], byte[]> source) { return new Map.Entry<HK, HV>() { @Override public HK getKey() { return deserializeHashKey(source.getKey()); } @Override public HV getValue() { return deserializeHashValue(source.getValue()); } @Override public HV setValue(HV value) { throw new UnsupportedOperationException( "Values cannot be set when scanning through entries."); } }; } }); } }, true); }
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public Long size(K key) { final byte[] rawKey = rawKey(key); return execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) { connection.select(dbIndex);/*www . j ava 2 s.c o m*/ return connection.strLen(rawKey); } }, true); }
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);// w w w . j ava2 s . c o m return connection.sUnion(rawKeys); } }, true); return deserializeValues(rawValues); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Get the value of {@code key}./* w ww.j a v a2 s . c o m*/ * <p> * See http://redis.io/commands/get * * @param <T> return object type * @param key must not be {@literal null}. * @param clazz clazz * @return value */ public <T> List<T> getList4Json(byte[] key, Class<T> clazz) { return redisTemplate.execute(new RedisCallback<List<T>>() { @Override public List<T> doInRedis(RedisConnection redis) throws DataAccessException { // return callback.transfer(redis.get(key)); byte[] value = redis.get(key); if (value == null) { return null; } return JsonUtils.toList(new String(value), clazz); } }); }