dev
This commit is contained in:
parent
eb7b06f98f
commit
f658520fe0
|
|
@ -15,7 +15,16 @@ public class RedisConfig {
|
|||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
// 设置 key 和 hashKey 使用 StringRedisSerializer
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
|
||||
// 设置 value 和 hashValue 使用 StringRedisSerializer
|
||||
template.setValueSerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(new StringRedisSerializer());
|
||||
|
||||
template.afterPropertiesSet();
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ public class CacheUtil {
|
|||
}
|
||||
|
||||
public <T> T get(String key, Class<T> clazz) {
|
||||
Object object = redisTemplate.opsForValue().get(key);
|
||||
T t = JSON.parseObject((String) object, clazz);
|
||||
return t;
|
||||
String json = (String) redisTemplate.opsForValue().get(key);
|
||||
if (json == null) return null;
|
||||
return JSON.parseObject(json, clazz);
|
||||
}
|
||||
|
||||
public JSONObject get(String key) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue