List of usage examples for org.springframework.data.redis.core RedisCallback RedisCallback
RedisCallback
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public Boolean multiSetIfAbsent(Map<? extends K, ? extends V> m) { if (m.isEmpty()) { return true; }/* www. ja v a 2 s.c o m*/ 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); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}.//from w ww . j a v a 2 s .com * <p> * See http://redis.io/commands/get * * @param key must not be {@literal null}. * @return value */ public static byte[] get(byte[] key) { return redisTemplate.execute(new RedisCallback<byte[]>() { @Override public byte[] doInRedis(RedisConnection redis) throws DataAccessException { return redis.get(key); } }); }
From source file:com.company.project.service.dao.RedisDao.java
public Long databaseSize() { return (Long) redisTemplate.execute(new RedisCallback<Long>() { @Override/*from w ww . java2 s . c om*/ public Long doInRedis(RedisConnection connection) throws DataAccessException { return connection.dbSize(); } }); }
From source file:io.gravitee.repository.redis.management.internal.impl.EventRedisRepositoryImpl.java
@Override public void delete(String event) { RedisEvent redisEvent = find(event); redisTemplate.executePipelined(new RedisCallback<Object>() { @Override//from w ww . ja v a 2 s . c o m public Object doInRedis(RedisConnection connection) throws DataAccessException { redisTemplate.opsForHash().delete(REDIS_KEY, event); redisTemplate.opsForSet().remove(REDIS_KEY + ":type:" + redisEvent.getType(), redisEvent.getId()); return null; } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Set<V> rangeByScore(K key, final double min, final double max) { final byte[] rawKey = rawKey(key); Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { public Set<byte[]> doInRedis(RedisConnection connection) { connection.select(dbIndex);//from w ww . j a va 2s . c o m return connection.zRangeByScore(rawKey, min, max); } }, true); return deserializeValues(rawValues); }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@SuppressWarnings("unchecked") @Override//from w w w . ja v a 2 s.c om public void evict(Object key) { final byte[] k = computeKey(key); template.execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) throws DataAccessException { connection.del(k); // remove key from set connection.zRem(setName, k); return null; } }, true); }
From source file:com.mauersu.util.redis.DefaultHashOperations.java
public void put(K key, HK hashKey, HV value) { final byte[] rawKey = rawKey(key); final byte[] rawHashKey = rawHashKey(hashKey); final byte[] rawHashValue = rawHashValue(value); execute(new RedisCallback<Object>() { public Object doInRedis(RedisConnection connection) { connection.select(dbIndex);//from w w w . j a va 2 s .com connection.hSet(rawKey, rawHashKey, rawHashValue); return null; } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}.// w ww . j a v a2s .c o m * <p> * See http://redis.io/commands/get * * @param key must not be {@literal null}. * @return value */ public static String get(String key) { return redisTemplate.execute(new RedisCallback<String>() { @Override public String doInRedis(RedisConnection redis) throws DataAccessException { byte[] value = redis.get(key.getBytes()); if (value == null) { return null; } return new String(value); } }); }
From source file:com.mauersu.util.redis.DefaultZSetOperations.java
public Set<V> rangeByScore(K key, final double min, final double max, final long offset, final long count) { final byte[] rawKey = rawKey(key); Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() { public Set<byte[]> doInRedis(RedisConnection connection) { connection.select(dbIndex);/*w ww .ja v a2 s . com*/ return connection.zRangeByScore(rawKey, min, max, offset, count); } }, true); return deserializeValues(rawValues); }
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);/*from w w w .jav a 2 s.c om*/ return connection.rPush(rawKey, rawValue); } }, true); }