diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/monitor/service/impl/RedisServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/monitor/service/impl/RedisServiceImpl.java index e5a439a6..c9dc6afc 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/monitor/service/impl/RedisServiceImpl.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/monitor/service/impl/RedisServiceImpl.java @@ -31,6 +31,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class RedisServiceImpl implements RedisService { + private static String CREATE_TIME ="create_time"; + private static String USER_MEMORY ="used_memory"; @Resource private RedisConnectionFactory redisConnectionFactory; @@ -40,6 +42,8 @@ public class RedisServiceImpl implements RedisService { @Override public List getRedisInfo() throws RedisConnectException { Properties info = redisConnectionFactory.getConnection().info(); + if(info==null) + return new ArrayList<>(); List infoList = new ArrayList<>(); RedisInfo redisInfo = null; for (Map.Entry entry : info.entrySet()) { @@ -55,7 +59,7 @@ public class RedisServiceImpl implements RedisService { public Map getKeysSize() throws RedisConnectException { Long dbSize = redisConnectionFactory.getConnection().dbSize(); Map map = new HashMap<>(); - map.put("create_time", System.currentTimeMillis()); + map.put(CREATE_TIME, System.currentTimeMillis()); map.put("dbSize", dbSize); log.info("--getKeysSize--: " + map.toString()); @@ -66,15 +70,17 @@ public class RedisServiceImpl implements RedisService { public Map getMemoryInfo() throws RedisConnectException { Map map = null; Properties info = redisConnectionFactory.getConnection().info(); + if(info==null) + return new HashMap<>(); for (Map.Entry entry : info.entrySet()) { String key = oConvertUtils.getString(entry.getKey()); - if ("used_memory".equals(key)) { + if (USER_MEMORY.equals(key)) { map = new HashMap<>(); - map.put("used_memory", entry.getValue()); - map.put("create_time", System.currentTimeMillis()); + map.put(USER_MEMORY, entry.getValue()); + map.put(CREATE_TIME, System.currentTimeMillis()); } } - log.info("--getMemoryInfo--: " + map.toString()); + log.info("--getMemoryInfo--: " + (map==null?":":map.toString())); return map; } @@ -109,10 +115,10 @@ public class RedisServiceImpl implements RedisService { jo.put("value",map.get("dbSize")); }else{ map = getMemoryInfo(); - Integer used_memory = Integer.valueOf(map.get("used_memory").toString()); + Integer used_memory = Integer.valueOf(map.get(USER_MEMORY).toString()); jo.put("value",used_memory/1000); } - String create_time = DateUtil.formatTime(DateUtil.date((Long) map.get("create_time")-(4-i)*1000)); + String create_time = DateUtil.formatTime(DateUtil.date((Long) map.get(CREATE_TIME)-(4-i)*1000)); jo.put("name",create_time); json.add(jo); }