package redis.clients.jedis;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import redis.clients.jedis.exceptions.JedisConnectionException;

public class JedisSlotBasedConnectionHandler extends JedisClusterConnectionHandler {

  public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes,
      final GenericObjectPoolConfig poolConfig, int timeout) {
    this(nodes, poolConfig, timeout, timeout);
  }

  public JedisSlotBasedConnectionHandler(Set<HostAndPort> nodes,
      final GenericObjectPoolConfig poolConfig, int connectionTimeout, int soTimeout) {
    super(nodes, poolConfig, connectionTimeout, soTimeout);
  }

  @Override
  public Jedis getConnection() {
    // In antirez's redis-rb-cluster implementation,
    // getRandomConnection always return valid connection (able to
    // ping-pong)
    // or exception if all connections are invalid

    List<JedisPool> pools = getShuffledNodesPool();

    for (JedisPool pool : pools) {
      Jedis jedis = null;
      try {
        jedis = pool.getResource();

        if (jedis == null) {
          continue;
        }

        String result = jedis.ping();

        if (result.equalsIgnoreCase("pong")) return jedis;

        pool.returnBrokenResource(jedis);
      } catch (JedisConnectionException ex) {
        if (jedis != null) {
          pool.returnBrokenResource(jedis);
        }
      }
    }

    throw new JedisConnectionException("no reachable node in cluster");
  }

  @Override
  public Jedis getConnectionFromSlot(int slot) {
    JedisPool connectionPool = cache.getSlotPool(slot);
    if (connectionPool != null) {
      // It can't guaranteed to get valid connection because of node
      // assignment
      return connectionPool.getResource();
    } else {
      return getConnection();
    }
  }
}

@@ -44,13 +44,8 @@
 til.
-Array
 List
@@ -57,139 +57,150 @@
 ort 
-java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport org.apache.commons.pool2.impl.GenericObjectPoolConfig;%0A
+org.apache.commons.pool2.impl.GenericObjectPoolConfig;%0A%0Aimport java.util.Set;%0A%0Aimport redis.clients.jedis.exceptions.JedisConnectionException;
 %0Aimp
@@ -235,34 +235,24 @@
 ptions.Jedis
-Connection
 Exception;%0A%0A
@@ -1350,34 +1350,24 @@
 catch (Jedis
-Connection
 Exception ex
@@ -1391,32 +1391,50 @@
 edis != null) %7B%0A
+          try %7B%0A  
           pool.r
@@ -1457,24 +1457,80 @@
 rce(jedis);%0A
+          %7D catch (JedisException silent) %7B%0A          %7D%0A
         %7D%0A  

Update JedisSlotBasedConnectionHandler.java