增加sonar测试并修复sonar测试的问题
This commit is contained in:
+1
-2
@@ -101,11 +101,10 @@ public class RedisAutoConfigure {
|
||||
}
|
||||
|
||||
private RedisCacheConfiguration getDefConf() {
|
||||
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
|
||||
return RedisCacheConfiguration.defaultCacheConfig()
|
||||
.disableCachingNullValues()
|
||||
.computePrefixWith(cacheName -> "cache".concat(":").concat(cacheName).concat(":"))
|
||||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
||||
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new RedisObjectSerializer()));
|
||||
return cacheConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -7,7 +7,9 @@ package com.central.common.redis.constant;
|
||||
* @date 2018/5/21 11:59
|
||||
*/
|
||||
public class RedisToolsConstant {
|
||||
|
||||
private RedisToolsConstant() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
/**
|
||||
* single Redis
|
||||
*/
|
||||
|
||||
+2
-1
@@ -56,7 +56,8 @@ public class RedisDistributedLock extends AbstractDistributedLock {
|
||||
log.debug("get redisDistributeLock failed, retrying..." + retryTimes);
|
||||
Thread.sleep(sleepMillis);
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
log.warn("Interrupted!", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
result = setRedis(key, expire);
|
||||
}
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@ public class RedisRepository {
|
||||
/**
|
||||
* 默认编码
|
||||
*/
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* key序列化
|
||||
|
||||
+10
-6
@@ -12,22 +12,26 @@ import org.springframework.data.redis.serializer.SerializationException;
|
||||
* @author zlt
|
||||
*/
|
||||
public class RedisObjectSerializer implements RedisSerializer<Object> {
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; // 做一个空数组,不是null
|
||||
// 做一个空数组,不是null
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
// 为了方便进行对象与字节数组的转换,所以应该首先准备出两个转换器
|
||||
private Converter<Object, byte[]> serializingConverter = new SerializingConverter();
|
||||
private Converter<byte[], Object> deserializingConverter = new DeserializingConverter();
|
||||
|
||||
@Override
|
||||
public byte[] serialize(Object obj) throws SerializationException {
|
||||
if (obj == null) { // 这个时候没有要序列化的对象出现,所以返回的字节数组应该就是一个空数组
|
||||
public byte[] serialize(Object obj) {
|
||||
// 这个时候没有要序列化的对象出现,所以返回的字节数组应该就是一个空数组
|
||||
if (obj == null) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
return this.serializingConverter.convert(obj); // 将对象变为字节数组
|
||||
// 将对象变为字节数组
|
||||
return this.serializingConverter.convert(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(byte[] data) throws SerializationException {
|
||||
if (data == null || data.length == 0) { // 此时没有对象的内容信息
|
||||
public Object deserialize(byte[] data) {
|
||||
// 此时没有对象的内容信息
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return this.deserializingConverter.convert(data);
|
||||
|
||||
Reference in New Issue
Block a user