Skip to content

Commit aa5e37d

Browse files
committed
Lettuce min-idle config does not work
1 parent 1f897ad commit aa5e37d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ private GenericObjectPoolConfig<?> getPoolConfig(Pool properties) {
146146
config.setMaxTotal(properties.getMaxActive());
147147
config.setMaxIdle(properties.getMaxIdle());
148148
config.setMinIdle(properties.getMinIdle());
149+
config.setTimeBetweenEvictionRunsMillis(
150+
properties.getIdleEvictPeriod().toMillis());
149151
if (properties.getMaxWait() != null) {
150152
config.setMaxWaitMillis(properties.getMaxWait().toMillis());
151153
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public static class Pool {
172172
/**
173173
* Target for the minimum number of idle connections to maintain in the pool. This
174174
* setting only has an effect if it is positive.
175+
*
176+
* This setting only has an effect if it is positive and `idleEvictPeriod` is
177+
* greater than zero.
175178
*/
176179
private int minIdle = 0;
177180

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

194+
/**
195+
* Time of milliseconds to sleep between runs of the idle object evictor thread.
196+
*
197+
* When positive, the idle object evictor thread starts. When non-positive, no
198+
* idle object evictor thread runs.
199+
*/
200+
private Duration idleEvictPeriod = Duration.ofMillis(-1);
201+
191202
public int getMaxIdle() {
192203
return this.maxIdle;
193204
}
@@ -220,6 +231,14 @@ public void setMaxWait(Duration maxWait) {
220231
this.maxWait = maxWait;
221232
}
222233

234+
public Duration getIdleEvictPeriod() {
235+
return this.idleEvictPeriod;
236+
}
237+
238+
public void setIdleEvictPeriod(Duration idleEvictPeriod) {
239+
this.idleEvictPeriod = idleEvictPeriod;
240+
}
241+
223242
}
224243

225244
/**

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.idle-evict-period: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)