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
8f7efbe1
Commit
8f7efbe1
authored
Dec 21, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish `spring.redis.url` support
See gh-7395
parent
90eb5825
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
RedisAutoConfiguration.java
...boot/autoconfigure/data/redis/RedisAutoConfiguration.java
+34
-23
RedisAutoConfigurationTests.java
...autoconfigure/data/redis/RedisAutoConfigurationTests.java
+3
-3
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.java
View file @
8f7efbe1
...
...
@@ -22,8 +22,6 @@ import java.net.UnknownHostException;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.pool2.impl.GenericObjectPool
;
import
redis.clients.jedis.Jedis
;
import
redis.clients.jedis.JedisPoolConfig
;
...
...
@@ -66,8 +64,6 @@ import org.springframework.util.StringUtils;
@EnableConfigurationProperties
(
RedisProperties
.
class
)
public
class
RedisAutoConfiguration
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
RedisAutoConfiguration
.
class
);
/**
* Redis connection configuration.
*/
...
...
@@ -98,21 +94,20 @@ public class RedisAutoConfiguration {
protected
final
JedisConnectionFactory
applyProperties
(
JedisConnectionFactory
factory
)
{
configureConnection
(
factory
);
if
(
this
.
properties
.
isSsl
())
{
factory
.
setUseSsl
(
true
);
}
factory
.
setDatabase
(
this
.
properties
.
getDatabase
());
if
(
this
.
properties
.
getTimeout
()
>
0
)
{
factory
.
setTimeout
(
this
.
properties
.
getTimeout
());
}
return
factory
;
}
private
void
configureConnection
(
JedisConnectionFactory
factory
)
{
if
(
StringUtils
.
hasText
(
this
.
properties
.
getUrl
()))
{
if
(
this
.
properties
.
getUrl
().
startsWith
(
"rediss://"
))
{
factory
.
setUseSsl
(
true
);
}
try
{
URI
redisURI
=
new
URI
(
this
.
properties
.
getUrl
());
factory
.
setHostName
(
redisURI
.
getHost
());
factory
.
setPort
(
redisURI
.
getPort
());
if
(
redisURI
.
getUserInfo
()
!=
null
)
{
factory
.
setPassword
(
redisURI
.
getUserInfo
().
split
(
":"
,
2
)[
1
]);
}
}
catch
(
URISyntaxException
e
)
{
logger
.
error
(
"Incorrect spring.redis.url"
,
e
);
}
configureConnectionFromUrl
(
factory
);
}
else
{
factory
.
setHostName
(
this
.
properties
.
getHost
());
...
...
@@ -121,14 +116,30 @@ public class RedisAutoConfiguration {
factory
.
setPassword
(
this
.
properties
.
getPassword
());
}
}
if
(
this
.
properties
.
isSsl
())
{
}
private
void
configureConnectionFromUrl
(
JedisConnectionFactory
factory
)
{
String
url
=
this
.
properties
.
getUrl
();
if
(
url
.
startsWith
(
"rediss://"
))
{
factory
.
setUseSsl
(
true
);
}
factory
.
setDatabase
(
this
.
properties
.
getDatabase
());
if
(
this
.
properties
.
getTimeout
()
>
0
)
{
factory
.
setTimeout
(
this
.
properties
.
getTimeout
());
try
{
URI
uri
=
new
URI
(
url
);
factory
.
setHostName
(
uri
.
getHost
());
factory
.
setPort
(
uri
.
getPort
());
if
(
uri
.
getUserInfo
()
!=
null
)
{
String
password
=
uri
.
getUserInfo
();
int
index
=
password
.
lastIndexOf
(
":"
);
if
(
index
>=
0
)
{
password
=
password
.
substring
(
index
+
1
);
}
factory
.
setPassword
(
password
);
}
}
catch
(
URISyntaxException
ex
)
{
throw
new
IllegalArgumentException
(
"Malformed 'spring.redis.url' "
+
url
,
ex
);
}
return
factory
;
}
protected
final
RedisSentinelConfiguration
getSentinelConfig
()
{
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java
View file @
8f7efbe1
...
...
@@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Christian Dupuis
* @author Christoph Strobl
* @author Eddú Meléndez
* @author Marco Aust
*/
public
class
RedisAutoConfigurationTests
{
...
...
@@ -76,10 +77,9 @@ public class RedisAutoConfigurationTests {
}
@Test
public
void
testOverrideU
RL
RedisConfiguration
()
throws
Exception
{
public
void
testOverrideU
rl
RedisConfiguration
()
throws
Exception
{
load
(
"spring.redis.host:foo"
,
"spring.redis.password:xyz"
,
"spring.redis.port:1000"
,
"spring.redis.ssl:true"
,
"spring.redis.port:1000"
,
"spring.redis.ssl:true"
,
"spring.redis.url:redis://user:password@example:33"
);
assertThat
(
this
.
context
.
getBean
(
JedisConnectionFactory
.
class
).
getHostName
())
.
isEqualTo
(
"example"
);
...
...
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