DATAREDIS-890 - Polishing.
Add author tags. Use try-with-resources to close Jedis. Original pull request: #373.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user