Commit 5b36484b authored by Phillip Webb's avatar Phillip Webb

Merge pull request #1433 from liujiong1982/spring-boot-1379

* spring-boot-1379:
  Add database property to RedisProperties
parents 2186da45 b1ceb8a4
......@@ -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