【fix sonar】RedisUtil文件
This commit is contained in:
+11
-13
@@ -1,9 +1,6 @@
|
|||||||
package com.jero.common.util;
|
package com.jero.common.util;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -320,7 +317,7 @@ public class RedisUtil {
|
|||||||
return redisTemplate.opsForSet().members(key);
|
return redisTemplate.opsForSet().members(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,8 +398,7 @@ public class RedisUtil {
|
|||||||
*/
|
*/
|
||||||
public long setRemove(String key, Object... values) {
|
public long setRemove(String key, Object... values) {
|
||||||
try {
|
try {
|
||||||
Long count = redisTemplate.opsForSet().remove(key, values);
|
return redisTemplate.opsForSet().remove(key, values);
|
||||||
return count;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -423,7 +419,7 @@ public class RedisUtil {
|
|||||||
return redisTemplate.opsForList().range(key, start, end);
|
return redisTemplate.opsForList().range(key, start, end);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,8 +560,7 @@ public class RedisUtil {
|
|||||||
*/
|
*/
|
||||||
public long lRemove(String key, long count, Object value) {
|
public long lRemove(String key, long count, Object value) {
|
||||||
try {
|
try {
|
||||||
Long remove = redisTemplate.opsForList().remove(key, count, value);
|
return redisTemplate.opsForList().remove(key, count, value);
|
||||||
return remove;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -592,11 +587,11 @@ public class RedisUtil {
|
|||||||
|
|
||||||
return binaryKeys;
|
return binaryKeys;
|
||||||
});
|
});
|
||||||
} catch (Throwable e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -606,8 +601,11 @@ public class RedisUtil {
|
|||||||
public void removeAll(String keyPrefix) {
|
public void removeAll(String keyPrefix) {
|
||||||
try {
|
try {
|
||||||
Set<String> keys = keys(keyPrefix);
|
Set<String> keys = keys(keyPrefix);
|
||||||
|
if(keys == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
redisTemplate.delete(keys);
|
redisTemplate.delete(keys);
|
||||||
} catch (Throwable e) {
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user