Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ private JedisPoolConfig jedisPoolConfig(RedisProperties.Pool pool) {
config.setMaxTotal(pool.getMaxActive());
config.setMaxIdle(pool.getMaxIdle());
config.setMinIdle(pool.getMinIdle());
if (pool.getTimeBetweenEvictionRuns() != null) {
config.setTimeBetweenEvictionRunsMillis(
pool.getTimeBetweenEvictionRuns().toMillis());
}
if (pool.getMaxWait() != null) {
config.setMaxWaitMillis(pool.getMaxWait().toMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ private GenericObjectPoolConfig<?> getPoolConfig(Pool properties) {
config.setMaxTotal(properties.getMaxActive());
config.setMaxIdle(properties.getMaxIdle());
config.setMinIdle(properties.getMinIdle());
if (properties.getTimeBetweenEvictionRuns() != null) {
config.setTimeBetweenEvictionRunsMillis(
properties.getTimeBetweenEvictionRuns().toMillis());
}
if (properties.getMaxWait() != null) {
config.setMaxWaitMillis(properties.getMaxWait().toMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public static class Pool {
/**
* Target for the minimum number of idle connections to maintain in the pool. This
* setting only has an effect if it is positive.
*
* This setting only has an effect if it is positive and `timeBetweenEvictionRuns`
* is greater than zero.
*/
private int minIdle = 0;

Expand All @@ -188,6 +191,14 @@ public static class Pool {
*/
private Duration maxWait = Duration.ofMillis(-1);

/**
* Time to sleep between runs of the idle object evictor thread.
*
* When positive, the idle object evictor thread starts. When non-positive, no
* idle object evictor thread runs.
*/
private Duration timeBetweenEvictionRuns;

public int getMaxIdle() {
return this.maxIdle;
}
Expand Down Expand Up @@ -220,6 +231,14 @@ public void setMaxWait(Duration maxWait) {
this.maxWait = maxWait;
}

public Duration getTimeBetweenEvictionRuns() {
return this.timeBetweenEvictionRuns;
}

public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) {
this.timeBetweenEvictionRuns = timeBetweenEvictionRuns;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,23 @@ public void testPasswordInUrlStartsWithColon() {

@Test
public void testRedisConfigurationWithPool() {
this.contextRunner.withPropertyValues("spring.redis.host:foo",
"spring.redis.jedis.pool.min-idle:1",
"spring.redis.jedis.pool.max-idle:4",
"spring.redis.jedis.pool.max-active:16",
"spring.redis.jedis.pool.max-wait:2000").run((context) -> {
this.contextRunner
.withPropertyValues("spring.redis.host:foo",
"spring.redis.jedis.pool.min-idle:1",
"spring.redis.jedis.pool.max-idle:4",
"spring.redis.jedis.pool.max-active:16",
"spring.redis.jedis.pool.max-wait:2000",
"spring.redis.jedis.pool.time-between-eviction-runs:30000")
.run((context) -> {
JedisConnectionFactory cf = context
.getBean(JedisConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo");
assertThat(cf.getPoolConfig().getMinIdle()).isEqualTo(1);
assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4);
assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16);
assertThat(cf.getPoolConfig().getMaxWaitMillis()).isEqualTo(2000);
assertThat(cf.getPoolConfig().getTimeBetweenEvictionRunsMillis())
.isEqualTo(30000);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void testRedisConfigurationWithPool() {
"spring.redis.lettuce.pool.max-idle:4",
"spring.redis.lettuce.pool.max-active:16",
"spring.redis.lettuce.pool.max-wait:2000",
"spring.redis.lettuce.pool.time-between-eviction-runs:30000",
"spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class);
Expand All @@ -165,6 +166,8 @@ public void testRedisConfigurationWithPool() {
assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
assertThat(poolConfig.getMaxWaitMillis()).isEqualTo(2000);
assertThat(poolConfig.getTimeBetweenEvictionRunsMillis())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to make an equivalent change to the tests for configuring Jedis as well?

Copy link
Contributor Author

@geminiKim geminiKim May 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same discussion as comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made an equivalent change to the tests for configuring Jedis.

.isEqualTo(30000);
assertThat(cf.getShutdownTimeout()).isEqualTo(1000);
});
}
Expand Down