RedisUtil.redisTemplate value serializer调整3
This commit is contained in:
parent
3dfaefeb44
commit
94fd3c5817
@ -20,6 +20,7 @@ import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -43,7 +44,24 @@ public class RedisUtil implements InitializingBean {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
RedisUtil.redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
|
||||
redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer(){
|
||||
@Override
|
||||
public byte[] serialize(Object object) throws SerializationException {
|
||||
return super.serialize(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(byte[] bytes) throws SerializationException {
|
||||
try {
|
||||
return super.deserialize(bytes);
|
||||
} catch (Exception e) {
|
||||
log.warn("object序列化出错,可能不是object类型,使用string序列化,exception:{}",e.getMessage());
|
||||
return new StringRedisSerializer().deserialize(bytes);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user