DATAREDIS-1127 - Handling ping failures for getSentinelConnection method.

Original Pull Request: #524
This commit is contained in:
Ajith Kumar
2020-04-20 20:30:53 +05:30
committed by Christoph Strobl
parent e6c4544b9a
commit 592db13541
2 changed files with 19 additions and 3 deletions

View File

@@ -75,6 +75,7 @@ import org.springframework.util.CollectionUtils;
* @author Christoph Strobl * @author Christoph Strobl
* @author Mark Paluch * @author Mark Paluch
* @author Fu Jian * @author Fu Jian
* @author Ajith Kumar
* @see JedisClientConfiguration * @see JedisClientConfiguration
* @see Jedis * @see Jedis
*/ */
@@ -855,10 +856,14 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
Jedis jedis = new Jedis(node.getHost(), node.getPort(), getConnectTimeout(), getReadTimeout()); Jedis jedis = new Jedis(node.getHost(), node.getPort(), getConnectTimeout(), getReadTimeout());
if (jedis.ping().equalsIgnoreCase("pong")) { try {
if (jedis.ping().equalsIgnoreCase("pong")) {
potentiallySetClientName(jedis); potentiallySetClientName(jedis);
return jedis; return jedis;
}
} catch (Exception ex) {
log.warn(String.format("Ping failed for sentinel host:%s", node.getHost()), ex);
} }
} }

View File

@@ -31,6 +31,7 @@ import org.springframework.data.redis.test.util.RedisSentinelRule;
* @author Christoph Strobl * @author Christoph Strobl
* @author Fu Jian * @author Fu Jian
* @author Mark Paluch * @author Mark Paluch
* @author Ajith Kumar
*/ */
public class JedisConnectionFactorySentinelIntegrationTests { public class JedisConnectionFactorySentinelIntegrationTests {
@@ -82,4 +83,14 @@ public class JedisConnectionFactorySentinelIntegrationTests {
assertThat(factory.getConnection().getClientName()).isEqualTo("clientName"); assertThat(factory.getConnection().getClientName()).isEqualTo("clientName");
} }
@Test
public void shouldNotFailOnFirstSentinelDown() {
final RedisSentinelConfiguration multiSentinelConfig = new RedisSentinelConfiguration()
.master("mymaster").sentinel("any.unavailable.host",26379).sentinel("127.0.0.1", 26379);
factory = new JedisConnectionFactory(multiSentinelConfig);
assertThat(factory.getSentinelConnection().isOpen()).isTrue();
}
} }