Commit b1ceb8a4 authored by David Liu's avatar David Liu Committed by Phillip Webb

Add database property to RedisProperties

Add database property to RedisProperties and use it in
RedisAutoConfiguration.

Fixes gh-1379
parent 2186da45
......@@ -65,6 +65,7 @@ public class RedisAutoConfiguration {
if (this.properties.getPassword() != null) {
factory.setPassword(this.properties.getPassword());
}
factory.setDatabase(this.properties.getDatabase());
return factory;
}
......@@ -86,6 +87,7 @@ public class RedisAutoConfiguration {
if (this.properties.getPassword() != null) {
factory.setPassword(this.properties.getPassword());
}
factory.setDatabase(this.properties.getDatabase());
return factory;
}
......
......@@ -26,6 +26,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {
private int database = 0;
private String host = "localhost";
private String password;
......@@ -66,6 +68,14 @@ public class RedisProperties {
this.pool = pool;
}
public int getDatabase() {
return this.database;
}
public void setDatabase(int database) {
this.database = database;
}
/**
* Pool properties.
*/
......
......@@ -51,11 +51,13 @@ public class RedisAutoConfigurationTests {
public void testOverrideRedisConfiguration() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.host:foo");
EnvironmentTestUtils.addEnvironment(this.context, "spring.redis.database: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).getDatabase());
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment