DATAREDIS-890 - Randomize Redis Cluster node order before topology retrieval.

We now shuffle the set of Redis Cluster nodes before retrieving the topology. This change reduces load on the first node in the known nodes set.

Original pull request: #373.
This commit is contained in:
ChenGuanqun
2018-11-20 21:55:21 +08:00
committed by Mark Paluch
parent dc0ce19cd0
commit 9d47c48e22
2 changed files with 15 additions and 9 deletions

View File

@@ -24,7 +24,9 @@ import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisClusterConnectionHandler;
import redis.clients.jedis.JedisPool;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -64,6 +66,7 @@ import org.springframework.util.Assert;
* @author Christoph Strobl
* @author Mark Paluch
* @author Ninad Divadkar
* @author Tao Chen
* @since 1.7
*/
public class JedisClusterConnection implements DefaultedRedisClusterConnection {
@@ -982,7 +985,9 @@ public class JedisClusterConnection implements DefaultedRedisClusterConnection {
Map<String, Exception> errors = new LinkedHashMap<>();
for (Entry<String, JedisPool> entry : cluster.getClusterNodes().entrySet()) {
List<Entry<String, JedisPool>> list = new ArrayList<>(cluster.getClusterNodes().entrySet());
Collections.shuffle(list);
for (Entry<String, JedisPool> entry : list) {
Jedis jedis = null;