List of usage examples for org.springframework.data.redis.connection RedisConnection get
@Nullable byte[] get(byte[] key);
From source file:com.github.deerapple.spring.redis.UserDao.java
@Override public User get(final String id) { User result = redisTemplate.execute(new RedisCallback<User>() { @Override/* w w w . ja v a 2 s . c om*/ public User doInRedis(RedisConnection rc) throws DataAccessException { RedisSerializer<String> serializer = getRedisSerializer(); byte[] key = serializer.serialize(id); byte[] value = rc.get(key); if (value == null) { return null; } String name = serializer.deserialize(value); return new User(id, name); } }); return result; }
From source file:com.zxy.commons.cache.RedisCache.java
@Override public ValueWrapper get(final Object key) { return redisTemplate.execute(new RedisCallback<ValueWrapper>() { public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException { byte[] keyb = SerializationUtils.serialize(key); byte[] value = connection.get(keyb); if (value == null) { return null; }//from ww w .j a va 2 s . c om return new SimpleValueWrapper(SerializationUtils.deserialize(value)); } }); }
From source file:com.mauersu.util.redis.DefaultValueOperations.java
public V get(final Object key) { return execute(new ValueDeserializingRedisCallback(key) { protected byte[] inRedis(byte[] rawKey, RedisConnection connection) { connection.select(dbIndex);// w w w .j av a 2s .c o m return connection.get(rawKey); } }, true); }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@Override public <T> T get(final Object key, Class<T> type) { return (T) template.execute(new RedisCallback<T>() { public T doInRedis(RedisConnection connection) throws DataAccessException { waitForLock(connection);/*from w ww . j a va 2s.c o m*/ byte[] bs = connection.get(computeKey(key)); return (T) template.getValueSerializer().deserialize(bs); } }, true); }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 2 s . c om*/ public ValueWrapper get(final Object key) { return (ValueWrapper) template.execute(new RedisCallback<ValueWrapper>() { public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException { waitForLock(connection); byte[] bs = connection.get(computeKey(key)); return (bs == null ? null : newValueWrapper(template.getValueSerializer().deserialize(bs))); } }, true); }
From source file:grails.plugin.cache.redis.GrailsRedisCache.java
@SuppressWarnings("unchecked") @Override//from www .j a v a2 s. com public ValueWrapper putIfAbsent(final Object key, final Object value) { final byte[] k = computeKey(key); return (ValueWrapper) template.execute(new RedisCallback<ValueWrapper>() { public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException { waitForLock(connection); byte[] bs = connection.get(computeKey(key)); if (bs == null) { connection.multi(); connection.set(k, template.getValueSerializer().serialize(value)); connection.zAdd(setName, 0, k); // Set key time to live when expiration has been configured. if (ttl > NEVER_EXPIRE) { connection.expire(k, ttl); connection.expire(setName, ttl); } connection.exec(); } bs = connection.get(computeKey(key)); return (bs == null ? null : newValueWrapper(template.getValueSerializer().deserialize(bs))); } }, true); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}./*from w ww. j a v a2 s.c o m*/ * <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.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}./*from w w w .jav a 2s . co 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.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}./*w w w . j a v a 2s.c o m*/ * <p> * See http://redis.io/commands/get * * @param <T> return object type * @param key must not be {@literal null}. * @param callback callback * @return value */ public static <T> T get(byte[] key, RedisTransferCallback<T> callback) { return redisTemplate.execute(new RedisCallback<T>() { @Override public T doInRedis(RedisConnection redis) throws DataAccessException { byte[] value = redis.get(key); if (value == null) { return null; } return callback.transfer(value); } }); }
From source file:com.zxy.commons.cache.RedisUtils.java
/** * Get the value of {@code key}.//from w ww . j a va 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> 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); } }); }