【Redis】【12】集羣不可用時,jedis 2.9.0版本超時時間12秒,升級版本修復

1. 2.9.0版本JedisSlotBasedConnectionHandler代碼

<dependency>
	<groupId>redis.clients</groupId>
	<artifactId>jedis</artifactId>
	<version>2.9.0</version>
</dependency>
 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 = cache.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;

        jedis.close();
      } catch (JedisException ex) {
        if (jedis != null) {
          jedis.close();
        }
      }
    }

    throw new JedisNoReachableClusterNodeException("No reachable node in cluster");
  }

2.3.0.0版本JedisSlotBasedConnectionHandler代碼

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>3.0.0</version>
</dependency>
public Jedis getConnection() {
	List<JedisPool> pools = this.cache.getShuffledNodesPool();
	Iterator var2 = pools.iterator();

	while(var2.hasNext()) {
		JedisPool pool = (JedisPool)var2.next();
		Jedis jedis = null;

		try {
			jedis = pool.getResource();
			if (jedis != null) {
				String result = jedis.ping();
				if (result.equalsIgnoreCase("pong")) {
					return jedis;
				}

				jedis.close();
			}
		} catch (JedisException var6) {
			if (jedis != null) {
				jedis.close();
			}
		}
	}

	throw new JedisNoReachableClusterNodeException("No reachable node in cluster");
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章