Authored by Xu

redisTemplate.keys 流异常处理

... ... @@ -170,11 +170,12 @@ public class MaliciousIpServiceImpl implements MaliciousIpService {
List<MaliciousIpLook> looks = new ArrayList<>();
MaliciousIpLook look;
try{
Set<String> values = redisReadMalicious.getIps();
Set<byte[]> values = redisReadMalicious.getIps();
if(CollectionUtils.isNotEmpty(values)){
for (String string : values) {
for (byte[] byt : values) {
String key = new String(byt);
look = new MaliciousIpLook();
look.setIp(string.substring("yh:mip:".length()));
look.setIp(key.substring("yh:mip:".length()));
looks.add(look);
}
response.setData(looks);
... ...
... ... @@ -34,8 +34,8 @@ public class RedisReadMaliciousUtil {
* 获取所有恶意ip集合
* @return
*/
public Set<String> getIps() {
Set<String> value = null;
public Set<byte[]> getIps() {
Set<byte[]> value = null;
try{
value = getKeysInRedisApi(redisReaderTemplate, MALICIOUS_IP);
}catch(Exception e){
... ... @@ -49,7 +49,7 @@ public class RedisReadMaliciousUtil {
* @param redisTemplate
* @param key
*/
private Set<String> getKeysInRedisApi(RedisTemplate<String, String> redisTemplate, String pattern){
return redisTemplate.keys(pattern);
private Set<byte[]> getKeysInRedisApi(RedisTemplate<String, String> redisTemplate, String pattern){
return redisTemplate.getConnectionFactory().getConnection().keys(pattern.getBytes());
}
}
\ No newline at end of file
... ...