parent
ebbd16788e
commit
202a426bd6
|
|
@ -99,6 +99,7 @@ abstract class RedisConnectionConfiguration {
|
|||
if (this.properties.getPassword() != null) {
|
||||
config.setPassword(RedisPassword.of(this.properties.getPassword()));
|
||||
}
|
||||
config.setSentinelUsername(sentinelProperties.getUsername());
|
||||
if (sentinelProperties.getPassword() != null) {
|
||||
config.setSentinelPassword(RedisPassword.of(sentinelProperties.getPassword()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -377,6 +377,11 @@ public class RedisProperties {
|
|||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Login username for authenticating with sentinel(s).
|
||||
*/
|
||||
private String username;
|
||||
|
||||
public String getMaster() {
|
||||
return this.master;
|
||||
}
|
||||
|
|
@ -401,6 +406,14 @@ public class RedisProperties {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -315,6 +315,25 @@ class RedisAutoConfigurationTests {
|
|||
assertThat(getUserName(connectionFactory)).isNull();
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
||||
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
||||
assertThat(sentinelConfiguration.getSentinelUsername()).isNull();
|
||||
assertThat(new String(sentinelConfiguration.getSentinelPassword().get())).isEqualTo("secret");
|
||||
Set<RedisNode> sentinels = sentinelConfiguration.getSentinels();
|
||||
assertThat(sentinels.stream().map(Object::toString).collect(Collectors.toSet()))
|
||||
.contains("127.0.0.1:26379", "127.0.0.1:26380");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedisConfigurationWithSentinelAuthenticationAndDataNodeAuthentication() {
|
||||
this.contextRunner.withPropertyValues("spring.redis.username=username", "spring.redis.password=password",
|
||||
"spring.redis.sentinel.username=sentinel", "spring.redis.sentinel.password=secret",
|
||||
"spring.redis.sentinel.master:mymaster",
|
||||
"spring.redis.sentinel.nodes:127.0.0.1:26379, 127.0.0.1:26380").run((context) -> {
|
||||
LettuceConnectionFactory connectionFactory = context.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(getUserName(connectionFactory)).isEqualTo("username");
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
||||
RedisSentinelConfiguration sentinelConfiguration = connectionFactory.getSentinelConfiguration();
|
||||
assertThat(sentinelConfiguration.getSentinelUsername()).isEqualTo("sentinel");
|
||||
assertThat(new String(sentinelConfiguration.getSentinelPassword().get())).isEqualTo("secret");
|
||||
Set<RedisNode> sentinels = sentinelConfiguration.getSentinels();
|
||||
assertThat(sentinels.stream().map(Object::toString).collect(Collectors.toSet()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue