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