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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user