redisTemplate.keys 流异常处理
Showing
2 changed files
with
8 additions
and
7 deletions
@@ -170,11 +170,12 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { | @@ -170,11 +170,12 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { | ||
170 | List<MaliciousIpLook> looks = new ArrayList<>(); | 170 | List<MaliciousIpLook> looks = new ArrayList<>(); |
171 | MaliciousIpLook look; | 171 | MaliciousIpLook look; |
172 | try{ | 172 | try{ |
173 | - Set<String> values = redisReadMalicious.getIps(); | 173 | + Set<byte[]> values = redisReadMalicious.getIps(); |
174 | if(CollectionUtils.isNotEmpty(values)){ | 174 | if(CollectionUtils.isNotEmpty(values)){ |
175 | - for (String string : values) { | 175 | + for (byte[] byt : values) { |
176 | + String key = new String(byt); | ||
176 | look = new MaliciousIpLook(); | 177 | look = new MaliciousIpLook(); |
177 | - look.setIp(string.substring("yh:mip:".length())); | 178 | + look.setIp(key.substring("yh:mip:".length())); |
178 | looks.add(look); | 179 | looks.add(look); |
179 | } | 180 | } |
180 | response.setData(looks); | 181 | response.setData(looks); |
@@ -34,8 +34,8 @@ public class RedisReadMaliciousUtil { | @@ -34,8 +34,8 @@ public class RedisReadMaliciousUtil { | ||
34 | * 获取所有恶意ip集合 | 34 | * 获取所有恶意ip集合 |
35 | * @return | 35 | * @return |
36 | */ | 36 | */ |
37 | - public Set<String> getIps() { | ||
38 | - Set<String> value = null; | 37 | + public Set<byte[]> getIps() { |
38 | + Set<byte[]> value = null; | ||
39 | try{ | 39 | try{ |
40 | value = getKeysInRedisApi(redisReaderTemplate, MALICIOUS_IP); | 40 | value = getKeysInRedisApi(redisReaderTemplate, MALICIOUS_IP); |
41 | }catch(Exception e){ | 41 | }catch(Exception e){ |
@@ -49,7 +49,7 @@ public class RedisReadMaliciousUtil { | @@ -49,7 +49,7 @@ public class RedisReadMaliciousUtil { | ||
49 | * @param redisTemplate | 49 | * @param redisTemplate |
50 | * @param key | 50 | * @param key |
51 | */ | 51 | */ |
52 | - private Set<String> getKeysInRedisApi(RedisTemplate<String, String> redisTemplate, String pattern){ | ||
53 | - return redisTemplate.keys(pattern); | 52 | + private Set<byte[]> getKeysInRedisApi(RedisTemplate<String, String> redisTemplate, String pattern){ |
53 | + return redisTemplate.getConnectionFactory().getConnection().keys(pattern.getBytes()); | ||
54 | } | 54 | } |
55 | } | 55 | } |
-
Please register or login to post a comment