diff --git a/backend/src/main/java/io/metersphere/consul/ConsulService.java b/backend/src/main/java/io/metersphere/consul/ConsulService.java index b02f2b662a..ab9c38b1c6 100644 --- a/backend/src/main/java/io/metersphere/consul/ConsulService.java +++ b/backend/src/main/java/io/metersphere/consul/ConsulService.java @@ -46,12 +46,10 @@ public class ConsulService { if (StringUtils.isNotEmpty(values)) { return objectMapper.readValue(values, TYPE_REFERENCE); } - Map> result = updateCache(); - stringRedisTemplate.opsForValue().set(RESOURCE_POOL_CACHE_KEY, objectMapper.writeValueAsString(result)); - return result; + return updateCache(); } - public Map> updateCache() { + public Map> updateCache() throws Exception { Map> result = new HashMap<>(); QueryResourcePoolRequest resourcePoolRequest = new QueryResourcePoolRequest(); @@ -89,6 +87,7 @@ public class ConsulService { result.put(node.getIp() + "-" + port, Collections.singletonList("metersphere")); } } + stringRedisTemplate.opsForValue().set(RESOURCE_POOL_CACHE_KEY, objectMapper.writeValueAsString(result)); return result; } }