Adapt to changes in Jedis 3.6.

Closes #2017
Original Pull Request: #2021
This commit is contained in:
Mark Paluch
2021-03-24 12:03:32 +01:00
committed by Christoph Strobl
parent 4a2abdcd9b
commit 284dfbcca6
6 changed files with 28 additions and 23 deletions

View File

@@ -274,7 +274,7 @@ class JedisClusterStreamCommands implements RedisStreamCommands {
try {
List<byte[]> response = connection.getCluster().xpending(key, group,
List<Object> response = connection.getCluster().xpending(key, group,
JedisConverters.toBytes(getLowerValue(range)), JedisConverters.toBytes(getUpperValue(range)),
options.getCount().intValue(), JedisConverters.toBytes(options.getConsumerName()));

View File

@@ -118,7 +118,7 @@ public class JedisConnection extends AbstractRedisConnection {
}
private static DefaultJedisClientConfig createConfig(int dbIndex, @Nullable String clientName) {
return DefaultJedisClientConfig.builder().databse(dbIndex).clientName(clientName).build();
return DefaultJedisClientConfig.builder().database(dbIndex).clientName(clientName).build();
}
/**

View File

@@ -281,7 +281,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
// force initialization (see Jedis issue #82)
jedis.connect();
potentiallySetClientName(jedis);
return jedis;
} catch (Exception ex) {
throw new RedisConnectionFailureException("Cannot get Jedis connection", ex);
@@ -361,7 +360,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
builder.connectionTimeoutMillis(getConnectTimeout());
builder.socketTimeoutMillis(getReadTimeout());
builder.databse(getDatabase());
builder.database(getDatabase());
if (!ObjectUtils.isEmpty(username)) {
builder.user(username);
@@ -498,8 +497,15 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
}
Jedis jedis = fetchJedisConnector();
JedisConnection connection = (getUsePool() ? new JedisConnection(jedis, pool, getDatabase(), getClientName())
: new JedisConnection(jedis, null, getDatabase(), getClientName()));
JedisClientConfig sentinelConfig = this.clientConfig;
SentinelConfiguration sentinelConfiguration = getSentinelConfiguration();
if (sentinelConfiguration != null) {
sentinelConfig = createClientConfig(null, sentinelConfiguration.getSentinelPassword());
}
JedisConnection connection = (getUsePool() ? new JedisConnection(jedis, pool, this.clientConfig, sentinelConfig)
: new JedisConnection(jedis, null, this.clientConfig, sentinelConfig));
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
return postProcessConnection(connection);
}
@@ -896,7 +902,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
return jedis;
}
} catch (Exception ex) {
log.warn(String.format("Ping failed for sentinel host:%s", node.getHost()), ex);
log.warn(String.format("Ping failed for sentinel host: %s", node.getHost()), ex);
} finally {
if (!success && jedis != null) {
jedis.close();
@@ -922,10 +928,6 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
return convertedNodes;
}
private void potentiallySetClientName(Jedis jedis) {
clientConfiguration.getClientName().ifPresent(jedis::clientSetname);
}
private int getReadTimeout() {
return Math.toIntExact(clientConfiguration.getReadTimeout().toMillis());
}

View File

@@ -87,7 +87,7 @@ class JedisConnectionFactorySentinelIntegrationTests {
void shouldNotFailOnFirstSentinelDown() {
RedisSentinelConfiguration oneDownSentinelConfig = new RedisSentinelConfiguration().master("mymaster")
.sentinel("any.unavailable.host", 26379).sentinel("127.0.0.1", 26379);
.sentinel("127.0.0.1", 1).sentinel("127.0.0.1", 26379);
factory = new JedisConnectionFactory(oneDownSentinelConfig);
assertThat(factory.getSentinelConnection().isOpen()).isTrue();

View File

@@ -18,6 +18,7 @@ package org.springframework.data.redis.connection.jedis;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisClusterConnectionHandler;
import redis.clients.jedis.JedisClusterInfoCache;
@@ -292,7 +293,7 @@ class JedisConnectionFactoryUnitTests {
assertThat(connectionFactory.getClusterConfiguration()).isSameAs(configuration);
}
@Test // DATAREDIS-974
@Test // DATAREDIS-974, GH-2017
void shouldApplySslConfigWhenCreatingClusterClient() throws NoSuchAlgorithmException {
SSLParameters sslParameters = new SSLParameters();
@@ -323,16 +324,17 @@ class JedisConnectionFactoryUnitTests {
JedisClusterConnectionHandler connectionHandler = (JedisClusterConnectionHandler) ReflectionTestUtils
.getField(cluster, "connectionHandler");
JedisClusterInfoCache cache = (JedisClusterInfoCache) ReflectionTestUtils.getField(connectionHandler, "cache");
JedisClientConfig clientConfig = (JedisClientConfig) ReflectionTestUtils.getField(cache, "clientConfig");
assertThat(ReflectionTestUtils.getField(cache, "connectionTimeout")).isEqualTo(60000);
assertThat(ReflectionTestUtils.getField(cache, "soTimeout")).isEqualTo(300000);
assertThat(ReflectionTestUtils.getField(cache, "password")).isNull();
assertThat(ReflectionTestUtils.getField(cache, "clientName")).isEqualTo("my-client");
assertThat(ReflectionTestUtils.getField(cache, "ssl")).isEqualTo(true);
assertThat(ReflectionTestUtils.getField(cache, "sslSocketFactory")).isEqualTo(socketFactory);
assertThat(ReflectionTestUtils.getField(cache, "sslParameters")).isEqualTo(sslParameters);
assertThat(ReflectionTestUtils.getField(cache, "hostnameVerifier")).isEqualTo(hostNameVerifier);
assertThat(ReflectionTestUtils.getField(cache, "hostAndPortMap")).isNull();
assertThat(clientConfig.getConnectionTimeoutMillis()).isEqualTo(60000);
assertThat(clientConfig.getSocketTimeoutMillis()).isEqualTo(300000);
assertThat(clientConfig.getPassword()).isNull();
assertThat(clientConfig.getClientName()).isEqualTo("my-client");
assertThat(clientConfig.isSsl()).isEqualTo(true);
assertThat(clientConfig.getSslSocketFactory()).isEqualTo(socketFactory);
assertThat(clientConfig.getSslParameters()).isEqualTo(sslParameters);
assertThat(clientConfig.getHostnameVerifier()).isEqualTo(hostNameVerifier);
assertThat(clientConfig.getHostAndPortMapper()).isNull();
}
@Test // DATAREDIS-574

View File

@@ -38,6 +38,7 @@ import org.springframework.data.redis.connection.RedisServerCommands.ShutdownOpt
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.test.util.ReflectionTestUtils;
/**
* @author Christoph Strobl
@@ -379,7 +380,7 @@ class JedisConnectionUnitTests {
MockedClientJedis(String host, Client client) {
super(host);
this.client = client;
ReflectionTestUtils.setField(this, "client", client);
}
}
}