Skip to content

Commit 5514192

Browse files
committed
Merge branch '2.1.x'
Closes gh-16809
2 parents bf294a7 + 75f4896 commit 5514192

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ private JedisPoolConfig jedisPoolConfig(RedisProperties.Pool pool) {
113113
config.setMaxTotal(pool.getMaxActive());
114114
config.setMaxIdle(pool.getMaxIdle());
115115
config.setMinIdle(pool.getMinIdle());
116+
if (pool.getTimeBetweenEvictionRuns() != null) {
117+
config.setTimeBetweenEvictionRunsMillis(
118+
pool.getTimeBetweenEvictionRuns().toMillis());
119+
}
116120
if (pool.getMaxWait() != null) {
117121
config.setMaxWaitMillis(pool.getMaxWait().toMillis());
118122
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ private GenericObjectPoolConfig<?> getPoolConfig(Pool properties) {
146146
config.setMaxTotal(properties.getMaxActive());
147147
config.setMaxIdle(properties.getMaxIdle());
148148
config.setMinIdle(properties.getMinIdle());
149+
if (properties.getTimeBetweenEvictionRuns() != null) {
150+
config.setTimeBetweenEvictionRunsMillis(
151+
properties.getTimeBetweenEvictionRuns().toMillis());
152+
}
149153
if (properties.getMaxWait() != null) {
150154
config.setMaxWaitMillis(properties.getMaxWait().toMillis());
151155
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -171,7 +171,8 @@ public static class Pool {
171171

172172
/**
173173
* Target for the minimum number of idle connections to maintain in the pool. This
174-
* setting only has an effect if it is positive.
174+
* setting only has an effect if both it and time between eviction runs are
175+
* positive.
175176
*/
176177
private int minIdle = 0;
177178

@@ -188,6 +189,12 @@ public static class Pool {
188189
*/
189190
private Duration maxWait = Duration.ofMillis(-1);
190191

192+
/**
193+
* Time between runs of the idle object evictor thread. When positive, the idle
194+
* object evictor thread starts, otherwise no idle object eviction is performed.
195+
*/
196+
private Duration timeBetweenEvictionRuns;
197+
191198
public int getMaxIdle() {
192199
return this.maxIdle;
193200
}
@@ -220,6 +227,14 @@ public void setMaxWait(Duration maxWait) {
220227
this.maxWait = maxWait;
221228
}
222229

230+
public Duration getTimeBetweenEvictionRuns() {
231+
return this.timeBetweenEvictionRuns;
232+
}
233+
234+
public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) {
235+
this.timeBetweenEvictionRuns = timeBetweenEvictionRuns;
236+
}
237+
223238
}
224239

225240
/**

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,23 @@ public void testPasswordInUrlStartsWithColon() {
134134

135135
@Test
136136
public void testRedisConfigurationWithPool() {
137-
this.contextRunner.withPropertyValues("spring.redis.host:foo",
138-
"spring.redis.jedis.pool.min-idle:1",
139-
"spring.redis.jedis.pool.max-idle:4",
140-
"spring.redis.jedis.pool.max-active:16",
141-
"spring.redis.jedis.pool.max-wait:2000").run((context) -> {
137+
this.contextRunner
138+
.withPropertyValues("spring.redis.host:foo",
139+
"spring.redis.jedis.pool.min-idle:1",
140+
"spring.redis.jedis.pool.max-idle:4",
141+
"spring.redis.jedis.pool.max-active:16",
142+
"spring.redis.jedis.pool.max-wait:2000",
143+
"spring.redis.jedis.pool.time-between-eviction-runs:30000")
144+
.run((context) -> {
142145
JedisConnectionFactory cf = context
143146
.getBean(JedisConnectionFactory.class);
144147
assertThat(cf.getHostName()).isEqualTo("foo");
145148
assertThat(cf.getPoolConfig().getMinIdle()).isEqualTo(1);
146149
assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4);
147150
assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16);
148151
assertThat(cf.getPoolConfig().getMaxWaitMillis()).isEqualTo(2000);
152+
assertThat(cf.getPoolConfig().getTimeBetweenEvictionRunsMillis())
153+
.isEqualTo(30000);
149154
});
150155
}
151156

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public void testRedisConfigurationWithPool() {
155155
"spring.redis.lettuce.pool.max-idle:4",
156156
"spring.redis.lettuce.pool.max-active:16",
157157
"spring.redis.lettuce.pool.max-wait:2000",
158+
"spring.redis.lettuce.pool.time-between-eviction-runs:30000",
158159
"spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
159160
LettuceConnectionFactory cf = context
160161
.getBean(LettuceConnectionFactory.class);
@@ -165,6 +166,8 @@ public void testRedisConfigurationWithPool() {
165166
assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
166167
assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
167168
assertThat(poolConfig.getMaxWaitMillis()).isEqualTo(2000);
169+
assertThat(poolConfig.getTimeBetweenEvictionRunsMillis())
170+
.isEqualTo(30000);
168171
assertThat(cf.getShutdownTimeout()).isEqualTo(1000);
169172
});
170173
}

0 commit comments

Comments
 (0)