Example usage for org.springframework.data.redis.connection RedisConnection get

List of usage examples for org.springframework.data.redis.connection RedisConnection get

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisConnection get.

Prototype

@Nullable
byte[] get(byte[] key);

Source Link

Document

Get the value of key .

Usage

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Get the value of {@code key}.//  w w w.  j ava  2 s  . com
 * <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.zxy.commons.cache.RedisUtils.java

/**
 * Get the value of {@code key}./*  w ww .  j a  v a  2  s .  co  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> Set<T> getSet4Json(byte[] key, Class<T> clazz) {
    return redisTemplate.execute(new RedisCallback<Set<T>>() {
        @Override
        public Set<T> doInRedis(RedisConnection redis) throws DataAccessException {
            //                return callback.transfer(redis.get(key));
            byte[] value = redis.get(key);
            if (value == null) {
                return null;
            }
            return JsonUtils.toSet(new String(value), clazz);
        }
    });
}

From source file:com.zxy.commons.cache.RedisUtils.java

/**
 * Get the value of {@code key}.//from w w w  . java 2s .  co  m
 * <p>
 * See http://redis.io/commands/get
 * 
 * @param <K> This is the key parameter
 * @param <V> This is the value parameter
 * @param key must not be {@literal null}.
 * @param keyClass key class
 * @param valueClass value class
 * @return value
*/
public static <K, V> Map<K, V> getMap4Json(byte[] key, Class<K> keyClass, Class<V> valueClass) {
    return redisTemplate.execute(new RedisCallback<Map<K, V>>() {
        @Override
        public Map<K, V> doInRedis(RedisConnection redis) throws DataAccessException {
            //                return callback.transfer(redis.get(key));
            byte[] value = redis.get(key);
            if (value == null) {
                return null;
            }
            return JsonUtils.toMap(new String(value), keyClass, valueClass);
        }
    });
}

From source file:com.zxy.commons.cache.RedisHelper.java

/**
 * Get the value of {@code key}.//from  w w w . j a va 2  s . c  o m
 * <p>
 * See http://redis.io/commands/get
 * 
 * @param key must not be {@literal null}.
 * @return value
 */
public 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.RedisHelper.java

/**
 * Get the value of {@code key}./*from ww  w  . j  a  v a2s .co  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 <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.RedisHelper.java

/**
 * Get the value of {@code key}.//w w  w. j  a  v a2s .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> 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.zxy.commons.cache.RedisHelper.java

/**
 * Get the value of {@code key}.//from  w w w .  ja va2 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> 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.zxy.commons.cache.RedisHelper.java

/**
 * Get the value of {@code key}.//ww  w  .  ja 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> Set<T> getSet4Json(byte[] key, Class<T> clazz) {
    return redisTemplate.execute(new RedisCallback<Set<T>>() {
        @Override
        public Set<T> doInRedis(RedisConnection redis) throws DataAccessException {
            //                return callback.transfer(redis.get(key));
            byte[] value = redis.get(key);
            if (value == null) {
                return null;
            }
            return JsonUtils.toSet(new String(value), clazz);
        }
    });
}

From source file:com.zxy.commons.cache.RedisHelper.java

/**
 * Get the value of {@code key}.//from   ww  w  .  j  av  a2s .  c  o  m
 * <p>
 * See http://redis.io/commands/get
 * 
 * @param <K> This is the key parameter
 * @param <V> This is the value parameter
 * @param key must not be {@literal null}.
 * @param keyClass key class
 * @param valueClass value class
 * @return value
*/
public <K, V> Map<K, V> getMap4Json(byte[] key, Class<K> keyClass, Class<V> valueClass) {
    return redisTemplate.execute(new RedisCallback<Map<K, V>>() {
        @Override
        public Map<K, V> doInRedis(RedisConnection redis) throws DataAccessException {
            //                return callback.transfer(redis.get(key));
            byte[] value = redis.get(key);
            if (value == null) {
                return null;
            }
            return JsonUtils.toMap(new String(value), keyClass, valueClass);
        }
    });
}

From source file:org.springframework.data.redis.cache.RedisCache.java

public ValueWrapper get(final Object key) {
    return (ValueWrapper) template.execute(new RedisCallback<ValueWrapper>() {

        public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException {
            waitForLock(connection);//from  www . j  a va 2s.c  o  m
            byte[] bs = connection.get(computeKey(key));
            Object value = template.getValueSerializer() != null ? template.getValueSerializer().deserialize(bs)
                    : bs;
            return (bs == null ? null : new SimpleValueWrapper(value));
        }
    }, true);
}