DATAREDIS-890 - Polishing.

Add author tags. Use try-with-resources to close Jedis.

Original pull request: #373.
This commit is contained in:
Mark Paluch
2018-11-23 10:14:37 +01:00
parent 9d47c48e22
commit 6921ab01bf
2 changed files with 10 additions and 12 deletions

View File

@@ -67,6 +67,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Ninad Divadkar
* @author Tao Chen
* @author Chen Guanqun
* @since 1.7
*/
public class JedisClusterConnection implements DefaultedRedisClusterConnection {
@@ -987,12 +988,10 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
List<Entry<String, JedisPool>> list = new ArrayList<>(cluster.getClusterNodes().entrySet());
Collections.shuffle(list);
for (Entry<String, JedisPool> entry : list) {
Jedis jedis = null;
try {
jedis = entry.getValue().getResource();
try (Jedis jedis = entry.getValue().getResource()) {
time = System.currentTimeMillis();
Set<RedisClusterNode> nodes = Converters.toSetOfRedisClusterNodes(jedis.clusterNodes());
@@ -1003,17 +1002,15 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
return cached;
} catch (Exception ex) {
errors.put(entry.getKey(), ex);
} finally {
if (jedis != null) {
jedis.close();
}
}
}
StringBuilder sb = new StringBuilder();
for (Entry<String, Exception> entry : errors.entrySet()) {
sb.append(String.format("\r\n\t- %s failed: %s", entry.getKey(), entry.getValue().getMessage()));
}
throw new ClusterStateFailureException(
"Could not retrieve cluster information. CLUSTER NODES returned with error." + sb.toString());
}