parent
b38601a2f2
commit
d8ec2719d7
|
@ -42,6 +42,7 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ JedisConnection.class, RedisOperations.class, Jedis.class })
|
@ConditionalOnClass({ JedisConnection.class, RedisOperations.class, Jedis.class })
|
||||||
|
@ -79,12 +80,13 @@ public class RedisAutoConfiguration {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
|
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
|
||||||
if (this.properties.getPool() != null) {
|
JedisConnectionFactory factory = null;
|
||||||
JedisConnectionFactory factory = new JedisConnectionFactory(
|
if (this.properties.getPool() == null) {
|
||||||
jedisPoolConfig());
|
factory = new JedisConnectionFactory();
|
||||||
return factory;
|
}
|
||||||
|
else {
|
||||||
|
factory = new JedisConnectionFactory(jedisPoolConfig());
|
||||||
}
|
}
|
||||||
JedisConnectionFactory factory = new JedisConnectionFactory();
|
|
||||||
factory.setHostName(this.properties.getHost());
|
factory.setHostName(this.properties.getHost());
|
||||||
factory.setPort(this.properties.getPort());
|
factory.setPort(this.properties.getPort());
|
||||||
if (this.properties.getPassword() != null) {
|
if (this.properties.getPassword() != null) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Christian Dupuis
|
||||||
*/
|
*/
|
||||||
public class RedisAutoConfigurationTests {
|
public class RedisAutoConfigurationTests {
|
||||||
|
|
||||||
|
@ -55,4 +56,18 @@ public class RedisAutoConfigurationTests {
|
||||||
.getHostName());
|
.getHostName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRedisConfigurationWithPool() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
|
||||||
|
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.pool.max-idle:1");
|
||||||
|
this.context.register(RedisAutoConfiguration.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
|
this.context.refresh();
|
||||||
|
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
|
||||||
|
.getHostName());
|
||||||
|
assertEquals(1, this.context.getBean(JedisConnectionFactory.class)
|
||||||
|
.getPoolConfig().getMaxIdle());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue