fix #553 : Overloading JedisCluster constructor to include poolConfig to be used internally for all JedisPool classes
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
|
||||
public class JedisCluster implements JedisCommands, BasicCommands {
|
||||
@@ -25,12 +26,28 @@ public class JedisCluster implements JedisCommands, BasicCommands {
|
||||
this(nodes, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> jedisClusterNode, int timeout,
|
||||
public JedisCluster(Set<HostAndPort> nodes, int timeout,
|
||||
int maxRedirections) {
|
||||
this.connectionHandler = new JedisSlotBasedConnectionHandler(
|
||||
jedisClusterNode);
|
||||
this.timeout = timeout;
|
||||
this.maxRedirections = maxRedirections;
|
||||
this(nodes, timeout, maxRedirections,
|
||||
new GenericObjectPoolConfig());
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> nodes,
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
this(nodes, DEFAULT_TIMEOUT, DEFAULT_MAX_REDIRECTIONS, poolConfig);
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> nodes, int timeout,
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
this(nodes, timeout, DEFAULT_MAX_REDIRECTIONS, poolConfig);
|
||||
}
|
||||
|
||||
public JedisCluster(Set<HostAndPort> jedisClusterNode, int timeout,
|
||||
int maxRedirections, final GenericObjectPoolConfig poolConfig) {
|
||||
this.connectionHandler = new JedisSlotBasedConnectionHandler(
|
||||
jedisClusterNode, poolConfig);
|
||||
this.timeout = timeout;
|
||||
this.maxRedirections = maxRedirections;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -9,12 +11,14 @@ public abstract class JedisClusterConnectionHandler {
|
||||
|
||||
protected Map<String, JedisPool> nodes = new HashMap<String, JedisPool>();
|
||||
protected Map<Integer, JedisPool> slots = new HashMap<Integer, JedisPool>();
|
||||
final protected GenericObjectPoolConfig poolConfig;
|
||||
|
||||
abstract Jedis getConnection();
|
||||
|
||||
abstract Jedis getConnectionFromSlot(int slot);
|
||||
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes) {
|
||||
public JedisClusterConnectionHandler(Set<HostAndPort> nodes, final GenericObjectPoolConfig poolConfig) {
|
||||
this.poolConfig = poolConfig;
|
||||
initializeSlotsCache(nodes);
|
||||
}
|
||||
|
||||
@@ -24,7 +28,7 @@ public abstract class JedisClusterConnectionHandler {
|
||||
|
||||
private void initializeSlotsCache(Set<HostAndPort> nodes) {
|
||||
for (HostAndPort hostAndPort : nodes) {
|
||||
JedisPool jp = new JedisPool(hostAndPort.getHost(),
|
||||
JedisPool jp = new JedisPool(poolConfig, hostAndPort.getHost(),
|
||||
hostAndPort.getPort());
|
||||
this.nodes.put(hostAndPort.getHost() + hostAndPort.getPort(), jp);
|
||||
Jedis jedis = jp.getResource();
|
||||
@@ -40,7 +44,7 @@ public abstract class JedisClusterConnectionHandler {
|
||||
String localNodes = jedis.clusterNodes();
|
||||
for (String nodeInfo : localNodes.split("\n")) {
|
||||
HostAndPort node = getHostAndPortFromNodeLine(nodeInfo, jedis);
|
||||
JedisPool nodePool = new JedisPool(node.getHost(), node.getPort());
|
||||
JedisPool nodePool = new JedisPool(poolConfig, node.getHost(), node.getPort());
|
||||
this.nodes.put(node.getHost() + node.getPort(), nodePool);
|
||||
populateNodeSlots(nodeInfo, nodePool);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisRandomConnectionHandler extends JedisClusterConnectionHandler {
|
||||
|
||||
public JedisRandomConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
super(nodes, new GenericObjectPoolConfig());
|
||||
}
|
||||
|
||||
public JedisRandomConnectionHandler(Set<HostAndPort> nodes,
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
super(nodes, poolConfig);
|
||||
}
|
||||
|
||||
public Jedis getConnection() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class JedisSlotBasedConnectionHandler extends
|
||||
@@ -7,8 +9,9 @@ public class JedisSlotBasedConnectionHandler extends
|
||||
|
||||
private Jedis currentConnection;
|
||||
|
||||
public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes,
|
||||
final GenericObjectPoolConfig poolConfig) {
|
||||
super(nodes, poolConfig);
|
||||
}
|
||||
|
||||
public Jedis getConnection() {
|
||||
|
||||
Reference in New Issue
Block a user