List of usage examples for org.springframework.data.redis.connection RedisConnection zRange
@Nullable Set<byte[]> zRange(byte[] key, long start, long end);
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Set<V> range(K key, final long start, final long end) { final byte[] rawKey = rawKey(key); Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { public Set<byte[]> doInRedis(RedisConnection connection) { connection.select(dbIndex);/* ww w.j a va2 s .c o m*/ return connection.zRange(rawKey, start, end); } }, true); return deserializeValues(rawValues); }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@SuppressWarnings("unchecked") @Override//from ww w . j a v a2 s.c om public Collection<Object> getAllKeys() { Set<byte[]> serializedKeys = (Set<byte[]>) template.execute(new RedisCallback<Set<byte[]>>() { public Set<byte[]> doInRedis(RedisConnection connection) throws DataAccessException { Set<byte[]> allKeys = new HashSet<byte[]>(); int offset = 0; boolean finished = false; while (!finished) { // need to paginate the keys Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - 1); allKeys.addAll(keys); finished = keys.size() < PAGE_SIZE; offset++; } return allKeys; } }, true); @SuppressWarnings("rawtypes") Collection<Object> keys = new HashSet(serializedKeys.size()); RedisSerializer<byte[]> keySerializer = template.getKeySerializer(); for (byte[] bytes : serializedKeys) { keys.add(keySerializer.deserialize(bytes)); } return keys; }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@SuppressWarnings("unchecked") @Override//w w w. j a v a 2 s. c o m public void clear() { // need to del each key individually template.execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) throws DataAccessException { // another clear is on-going if (connection.exists(cacheLockName)) { return null; } try { connection.set(cacheLockName, cacheLockName); int offset = 0; boolean finished = false; do { // need to paginate the keys Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - 1); finished = keys.size() < PAGE_SIZE; offset++; if (!keys.isEmpty()) { connection.del(keys.toArray(new byte[keys.size()][])); } } while (!finished); connection.del(setName); return null; } finally { connection.del(cacheLockName); } } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get elements between {@code begin} and {@code end} from sorted set. * <p>//from w w w. j a v a 2s . c o m * See http://redis.io/commands/zrange * * @param key key * @param begin begin * @param end end * @return Set<byte[]> */ public static Set<byte[]> zRange(byte[] key, long begin, long end) { return redisTemplate.execute(new RedisCallback<Set<byte[]>>() { @Override public Set<byte[]> doInRedis(RedisConnection redis) throws DataAccessException { return redis.zRange(key, begin, end); } }); }
From source file:com.zxy.commons.cache.RedisHelper.java
/** * Get elements between {@code begin} and {@code end} from sorted set. * <p>/*from ww w .jav a 2 s .co m*/ * See http://redis.io/commands/zrange * * @param key key * @param begin begin * @param end end * @return Set<byte[]> */ public Set<byte[]> zRange(byte[] key, long begin, long end) { return redisTemplate.execute(new RedisCallback<Set<byte[]>>() { @Override public Set<byte[]> doInRedis(RedisConnection redis) throws DataAccessException { return redis.zRange(key, begin, end); } }); }
From source file:org.springframework.data.redis.cache.RedisCache.java
public void clear() { // need to del each key individually template.execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) throws DataAccessException { // another clear is on-going if (connection.exists(cacheLockName)) { return null; }//w ww. ja va 2s . com try { connection.set(cacheLockName, cacheLockName); int offset = 0; boolean finished = false; do { // need to paginate the keys Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE, (offset + 1) * PAGE_SIZE - 1); finished = keys.size() < PAGE_SIZE; offset++; if (!keys.isEmpty()) { connection.del(keys.toArray(new byte[keys.size()][])); } } while (!finished); connection.del(setName); return null; } finally { connection.del(cacheLockName); } } }, true); }