diff --git a/src/main/java/redis/clients/jedis/Connection.java b/src/main/java/redis/clients/jedis/Connection.java index a0a342e8ab..765cf609fe 100644 --- a/src/main/java/redis/clients/jedis/Connection.java +++ b/src/main/java/redis/clients/jedis/Connection.java @@ -81,7 +81,7 @@ public final void setHandlingPool(final ConnectionPool pool) { this.memberOf = pool; } - final HostAndPort getHostAndPort() { + public HostAndPort getHostAndPort() { return ((DefaultJedisSocketFactory) socketFactory).getHostAndPort(); } diff --git a/src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java b/src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java index f9c7cd2228..df54bc88a7 100644 --- a/src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java +++ b/src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java @@ -60,7 +60,7 @@ private Socket connectToFirstSuccessfulHost(HostAndPort hostAndPort) throws Exce Collections.shuffle(hosts); } - JedisConnectionException jce = new JedisConnectionException("Failed to connect to any host resolved for DNS name."); + JedisConnectionException jce = new JedisConnectionException("Failed to connect to host " + hostAndPort); for (InetAddress host : hosts) { try { Socket socket = new Socket(); diff --git a/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java b/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java index 48ed4cd6a0..d71e3bbbcf 100644 --- a/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java +++ b/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java @@ -96,7 +96,8 @@ public final T executeCommand(CommandObject commandObject) { } catch (JedisClusterOperationException jnrcne) { throw jnrcne; } catch (JedisConnectionException jce) { - lastException = jce; + lastException = new JedisConnectionException( + "Cluster retry failed to " + (connection != null ? connection.getHostAndPort().toString() : ""), jce); ++consecutiveConnectionFailures; log.debug("Failed connecting to Redis: {}", connection, jce); // "- 1" because we just did one, but the attemptsLeft counter hasn't been decremented yet @@ -122,7 +123,9 @@ public final T executeCommand(CommandObject commandObject) { IOUtils.closeQuietly(connection); } if (Instant.now().isAfter(deadline)) { - throw new JedisClusterOperationException("Cluster retry deadline exceeded."); + throw new JedisClusterOperationException( + "Cluster retry to " + (connection != null ? connection.getHostAndPort().toString() : "") + + " deadline exceeded."); } } diff --git a/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java b/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java index f4f9002539..cb4d749db3 100644 --- a/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java +++ b/src/main/java/redis/clients/jedis/executors/RetryableCommandExecutor.java @@ -48,7 +48,8 @@ public final T executeCommand(CommandObject commandObject) { return execute(connection, commandObject); } catch (JedisConnectionException jce) { - lastException = jce; + lastException = new JedisConnectionException( + "Retry failed to " + (connection != null ? connection.getHostAndPort().toString() : ""), jce); ++consecutiveConnectionFailures; log.debug("Failed connecting to Redis: {}", connection, jce); // "- 1" because we just did one, but the attemptsLeft counter hasn't been decremented yet @@ -62,7 +63,8 @@ public final T executeCommand(CommandObject commandObject) { } } if (Instant.now().isAfter(deadline)) { - throw new JedisException("Retry deadline exceeded."); + throw new JedisException("Retry to " + (connection != null ? connection.getHostAndPort().toString() : "") + + " deadline exceeded."); } }