Make JedisCluster multihread by improving connection handling
This commit is contained in:
@@ -5,25 +5,12 @@ import java.util.Set;
|
||||
public class JedisSlotBasedConnectionHandler extends
|
||||
JedisClusterConnectionHandler {
|
||||
|
||||
private Jedis currentConnection;
|
||||
|
||||
public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes) {
|
||||
super(nodes);
|
||||
}
|
||||
|
||||
public Jedis getConnection() {
|
||||
return currentConnection != null ? currentConnection
|
||||
: getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
private void returnCurrentConnection() {
|
||||
if (currentConnection != null) {
|
||||
nodes.get(
|
||||
currentConnection.getClient().getHost()
|
||||
+ currentConnection.getClient().getPort())
|
||||
.returnResource(currentConnection);
|
||||
}
|
||||
|
||||
return getRandomConnection().getResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,13 +21,11 @@ public class JedisSlotBasedConnectionHandler extends
|
||||
|
||||
@Override
|
||||
public Jedis getConnectionFromSlot(int slot) {
|
||||
returnCurrentConnection();
|
||||
JedisPool connectionPool = slots.get(slot);
|
||||
if (connectionPool == null) {
|
||||
connectionPool = getRandomConnection();
|
||||
}
|
||||
currentConnection = connectionPool.getResource();
|
||||
return connectionPool.getResource();
|
||||
return connectionPool.getResource();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user