Skip to content

Commit d8ec271

Browse files
committed
Fix RedisAutoConfiguration with pool config
fixes #850
1 parent b38601a commit d8ec271

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfiguration.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
*
4343
* @author Dave Syer
4444
* @author Andy Wilkinson
45+
* @author Christian Dupuis
4546
*/
4647
@Configuration
4748
@ConditionalOnClass({ JedisConnection.class, RedisOperations.class, Jedis.class })
@@ -79,12 +80,13 @@ protected static class RedisPooledConnectionConfiguration {
7980
@Bean
8081
@ConditionalOnMissingBean
8182
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
82-
if (this.properties.getPool() != null) {
83-
JedisConnectionFactory factory = new JedisConnectionFactory(
84-
jedisPoolConfig());
85-
return factory;
83+
JedisConnectionFactory factory = null;
84+
if (this.properties.getPool() == null) {
85+
factory = new JedisConnectionFactory();
86+
}
87+
else {
88+
factory = new JedisConnectionFactory(jedisPoolConfig());
8689
}
87-
JedisConnectionFactory factory = new JedisConnectionFactory();
8890
factory.setHostName(this.properties.getHost());
8991
factory.setPort(this.properties.getPort());
9092
if (this.properties.getPassword() != null) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/redis/RedisAutoConfigurationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @author Dave Syer
32+
* @author Christian Dupuis
3233
*/
3334
public class RedisAutoConfigurationTests {
3435

@@ -55,4 +56,18 @@ public void testOverrideRedisConfiguration() throws Exception {
5556
.getHostName());
5657
}
5758

59+
@Test
60+
public void testRedisConfigurationWithPool() throws Exception {
61+
this.context = new AnnotationConfigApplicationContext();
62+
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
63+
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.pool.max-idle:1");
64+
this.context.register(RedisAutoConfiguration.class,
65+
PropertyPlaceholderAutoConfiguration.class);
66+
this.context.refresh();
67+
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
68+
.getHostName());
69+
assertEquals(1, this.context.getBean(JedisConnectionFactory.class)
70+
.getPoolConfig().getMaxIdle());
71+
}
72+
5873
}

0 commit comments

Comments
 (0)