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