redis.clients.jedis.exceptions.JedisRedirectionException Java Examples

The following examples show how to use redis.clients.jedis.exceptions.JedisRedirectionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnhancedJedisClusterCommand.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
@Override
public T execute(Jedis connection) {
	try {
		return doExecute(connection);
	} catch (JedisException e) {
		/**
		 * {@link redis.clients.jedis.JedisClusterCommand#runWithRetries}
		 */
		if ((e instanceof JedisRedirectionException) || (e instanceof JedisNoReachableClusterNodeException)) {
			throw e;
		}
		// Print details errors.
		String node = connection.getClient().getHost() + ":" + connection.getClient().getPort();
		String errmsg = format("Couldn't execution jedis command of node: %s", node);
		if (e instanceof JedisConnectionException) {
			throw new JedisConnectionException(errmsg, e);
		}
		throw new JedisException(errmsg, e);
	}
}
 
Example #2
Source File: PipelineClusterCommand.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
protected boolean checkException(Object obj) {
    if (obj instanceof Exception) {
        Exception e = (Exception) obj;
        if (e instanceof JedisRedirectionException) {
            //重定向slot 映射.
            if (e instanceof JedisMovedDataException) {
                // it rebuilds cluster's slot cache
                // recommended by Redis cluster specification
                this.connectionHandler.renewSlotCache();
                logger.warn("JedisMovedDataException:" + e.getMessage(), e);
            } else {
                logger.error("pipeline-error:" + e.getMessage(), e);
            }
        } else {
            logger.error(e.getMessage(), e);
        }
        return true;
    }
    return false;
}
 
Example #3
Source File: JedisClusterPipeline.java    From AutoLoadCache with Apache License 2.0 6 votes vote down vote up
private void innerSync(List<Object> formatted) {
    try {
        Response<?> response;
        Object data;
        for (Client client : clients) {
            response = generateResponse(client.getOne());
            if (null != formatted) {
                data = response.get();
                formatted.add(data);
            }
        }
    } catch (JedisRedirectionException jre) {
        throw jre;
    } finally {
        close();
    }
}
 
Example #4
Source File: JedisClusterCommand.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
private T runWithRetries(byte[] key, int redirections, boolean tryRandomNode, boolean asking) {
  if (redirections <= 0) {
      JedisClusterMaxRedirectionsException exception = new JedisClusterMaxRedirectionsException("Too many Cluster redirections? key=" + SafeEncoder.encode(key));
      //收集
      UsefulDataCollector.collectException(exception, "", System.currentTimeMillis(), ClientExceptionType.REDIS_CLUSTER);
      throw exception;
  }

  Jedis connection = null;
  try {

    if (asking) {
      // TODO: Pipeline asking with the original command to make it
      // faster....
      connection = askConnection.get();
      connection.asking();

      // if asking success, reset asking flag
      asking = false;
    } else {
      if (tryRandomNode) {
        connection = connectionHandler.getConnection();
      } else {
        connection = connectionHandler.getConnectionFromSlot(JedisClusterCRC16.getSlot(key));
      }
    }

    return execute(connection);
  } catch (JedisConnectionException jce) {
    if (tryRandomNode) {
      // maybe all connection is down
      throw jce;
    }

    // release current connection before recursion
    releaseConnection(connection);
    connection = null;

    // retry with random connection
    return runWithRetries(key, redirections - 1, true, asking);
  } catch (JedisRedirectionException jre) {
    // if MOVED redirection occurred,
    if (jre instanceof JedisMovedDataException) {
      // it rebuilds cluster's slot cache
      // recommended by Redis cluster specification
      this.connectionHandler.renewSlotCache(connection);
    }

    // release current connection before recursion or renewing
    releaseConnection(connection);
    connection = null;

    if (jre instanceof JedisAskDataException) {
      asking = true;
      askConnection.set(this.connectionHandler.getConnectionFromNode(jre.getTargetNode()));
    } else if (jre instanceof JedisMovedDataException) {
    } else {
      throw new JedisClusterException(jre);
    }

    return runWithRetries(key, redirections - 1, false, asking);
  } finally {
    releaseConnection(connection);
  }
}