Commit 557361c9 authored by Stephane Nicoll's avatar Stephane Nicoll

Properly set redis password for Cluster and Sentinel config

Closes gh-9583
parent 1a839d66
......@@ -79,6 +79,9 @@ abstract class RedisConnectionConfiguration {
RedisSentinelConfiguration config = new RedisSentinelConfiguration();
config.master(sentinelProperties.getMaster());
config.setSentinels(createSentinels(sentinelProperties));
if (this.properties.getPassword() != null) {
config.setPassword(RedisPassword.of(this.properties.getPassword()));
}
return config;
}
return null;
......@@ -101,6 +104,9 @@ abstract class RedisConnectionConfiguration {
if (clusterProperties.getMaxRedirects() != null) {
config.setMaxRedirects(clusterProperties.getMaxRedirects());
}
if (this.properties.getPassword() != null) {
config.setPassword(RedisPassword.of(this.properties.getPassword()));
}
return config;
}
......
......@@ -125,6 +125,16 @@ public class RedisAutoConfigurationJedisTests {
.isRedisSentinelAware()).isTrue();
}
@Test
public void testRedisConfigurationWithSentinelAndPassword() {
List<String> sentinels = Arrays.asList("127.0.0.1:26379", "127.0.0.1:26380");
load("spring.redis.password=password", "spring.redis.sentinel.master:mymaster",
"spring.redis.sentinel.nodes:" + StringUtils
.collectionToCommaDelimitedString(sentinels));
assertThat(this.context.getBean(JedisConnectionFactory.class)
.getPassword()).isEqualTo("password");
}
@Test
public void testRedisConfigurationWithCluster() throws Exception {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
......
......@@ -148,6 +148,16 @@ public class RedisAutoConfigurationTests {
.isRedisSentinelAware()).isTrue();
}
@Test
public void testRedisConfigurationWithSentinelAndPassword() throws Exception {
List<String> sentinels = Arrays.asList("127.0.0.1:26379", "127.0.0.1:26380");
load("spring.redis.password=password", "spring.redis.sentinel.master:mymaster",
"spring.redis.sentinel.nodes:"
+ StringUtils.collectionToCommaDelimitedString(sentinels));
assertThat(this.context.getBean(LettuceConnectionFactory.class)
.getPassword()).isEqualTo("password");
}
@Test
public void testRedisConfigurationWithCluster() throws Exception {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
......@@ -157,6 +167,16 @@ public class RedisAutoConfigurationTests {
.getClusterConnection()).isNotNull();
}
@Test
public void testRedisConfigurationWithClusterAndPassword() throws Exception {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
load("spring.redis.password=password",
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1));
assertThat(this.context.getBean(LettuceConnectionFactory.class)
.getPassword()).isEqualTo("password");
}
private DefaultLettucePool getDefaultLettucePool(LettuceConnectionFactory factory) {
return (DefaultLettucePool) ReflectionTestUtils.getField(factory, "pool");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment