Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
5acd115c
Commit
5acd115c
authored
May 13, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add redis sentinel password property
Closes gh-21353
parent
038ae934
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
RedisConnectionConfiguration.java
...utoconfigure/data/redis/RedisConnectionConfiguration.java
+4
-1
RedisProperties.java
...mework/boot/autoconfigure/data/redis/RedisProperties.java
+13
-0
RedisAutoConfigurationTests.java
...autoconfigure/data/redis/RedisAutoConfigurationTests.java
+19
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java
View file @
5acd115c
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -82,6 +82,9 @@ abstract class RedisConnectionConfiguration {
if
(
this
.
properties
.
getPassword
()
!=
null
)
{
config
.
setPassword
(
RedisPassword
.
of
(
this
.
properties
.
getPassword
()));
}
if
(
sentinelProperties
.
getPassword
()
!=
null
)
{
config
.
setSentinelPassword
(
RedisPassword
.
of
(
sentinelProperties
.
getPassword
()));
}
config
.
setDatabase
(
this
.
properties
.
getDatabase
());
return
config
;
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java
View file @
5acd115c
...
...
@@ -301,6 +301,11 @@ public class RedisProperties {
*/
private
List
<
String
>
nodes
;
/**
* Password for authenticating with sentinel(s).
*/
private
String
password
;
public
String
getMaster
()
{
return
this
.
master
;
}
...
...
@@ -317,6 +322,14 @@ public class RedisProperties {
this
.
nodes
=
nodes
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java
View file @
5acd115c
...
...
@@ -37,6 +37,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisClusterConfiguration
;
import
org.springframework.data.redis.connection.RedisNode
;
import
org.springframework.data.redis.connection.RedisSentinelConfiguration
;
import
org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration
;
import
org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration.LettuceClientConfigurationBuilder
;
import
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory
;
...
...
@@ -199,17 +200,34 @@ class RedisAutoConfigurationTests {
}
@Test
void
testRedisConfigurationWithSentinelAndPassword
()
{
void
testRedisConfigurationWithSentinelAnd
DataNode
Password
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.redis.password=password"
,
"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
(
connectionFactory
.
getPassword
()).
isEqualTo
(
"password"
);
RedisSentinelConfiguration
sentinelConfiguration
=
connectionFactory
.
getSentinelConfiguration
();
assertThat
(
sentinelConfiguration
.
getSentinelPassword
().
isPresent
()).
isFalse
();
Set
<
RedisNode
>
sentinels
=
connectionFactory
.
getSentinelConfiguration
().
getSentinels
();
assertThat
(
sentinels
.
stream
().
map
(
Object:
:
toString
).
collect
(
Collectors
.
toSet
()))
.
contains
(
"127.0.0.1:26379"
,
"127.0.0.1:26380"
);
});
}
@Test
void
testRedisConfigurationWithSentinelPasswordAndDataNodePassword
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.redis.password=password"
,
"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
(
connectionFactory
.
getPassword
()).
isEqualTo
(
"password"
);
RedisSentinelConfiguration
sentinelConfiguration
=
connectionFactory
.
getSentinelConfiguration
();
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
testRedisConfigurationWithCluster
()
{
List
<
String
>
clusterNodes
=
Arrays
.
asList
(
"127.0.0.1:27379"
,
"127.0.0.1:27380"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment