Commit 75f48964 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge pull request #16703 from Gemini Kim

* gh-16703:
  Polish "Enable minIdle by allowing timeBetweenEviction runs to be configured"
  Enable minIdle by allowing timeBetweenEviction runs to be configured

Closes gh-16703
parents 509d338d 96f3a482
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -114,6 +114,10 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration { ...@@ -114,6 +114,10 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
config.setMaxTotal(pool.getMaxActive()); config.setMaxTotal(pool.getMaxActive());
config.setMaxIdle(pool.getMaxIdle()); config.setMaxIdle(pool.getMaxIdle());
config.setMinIdle(pool.getMinIdle()); config.setMinIdle(pool.getMinIdle());
if (pool.getTimeBetweenEvictionRuns() != null) {
config.setTimeBetweenEvictionRunsMillis(
pool.getTimeBetweenEvictionRuns().toMillis());
}
if (pool.getMaxWait() != null) { if (pool.getMaxWait() != null) {
config.setMaxWaitMillis(pool.getMaxWait().toMillis()); config.setMaxWaitMillis(pool.getMaxWait().toMillis());
} }
......
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -155,6 +155,10 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration { ...@@ -155,6 +155,10 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
config.setMaxTotal(properties.getMaxActive()); config.setMaxTotal(properties.getMaxActive());
config.setMaxIdle(properties.getMaxIdle()); config.setMaxIdle(properties.getMaxIdle());
config.setMinIdle(properties.getMinIdle()); config.setMinIdle(properties.getMinIdle());
if (properties.getTimeBetweenEvictionRuns() != null) {
config.setTimeBetweenEvictionRunsMillis(
properties.getTimeBetweenEvictionRuns().toMillis());
}
if (properties.getMaxWait() != null) { if (properties.getMaxWait() != null) {
config.setMaxWaitMillis(properties.getMaxWait().toMillis()); config.setMaxWaitMillis(properties.getMaxWait().toMillis());
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -171,7 +171,8 @@ public class RedisProperties { ...@@ -171,7 +171,8 @@ public class RedisProperties {
/** /**
* Target for the minimum number of idle connections to maintain in the pool. This * Target for the minimum number of idle connections to maintain in the pool. This
* setting only has an effect if it is positive. * setting only has an effect if both it and time between eviction runs are
* positive.
*/ */
private int minIdle = 0; private int minIdle = 0;
...@@ -188,6 +189,12 @@ public class RedisProperties { ...@@ -188,6 +189,12 @@ public class RedisProperties {
*/ */
private Duration maxWait = Duration.ofMillis(-1); private Duration maxWait = Duration.ofMillis(-1);
/**
* Time between runs of the idle object evictor thread. When positive, the idle
* object evictor thread starts, otherwise no idle object eviction is performed.
*/
private Duration timeBetweenEvictionRuns;
public int getMaxIdle() { public int getMaxIdle() {
return this.maxIdle; return this.maxIdle;
} }
...@@ -220,6 +227,14 @@ public class RedisProperties { ...@@ -220,6 +227,14 @@ public class RedisProperties {
this.maxWait = maxWait; this.maxWait = maxWait;
} }
public Duration getTimeBetweenEvictionRuns() {
return this.timeBetweenEvictionRuns;
}
public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) {
this.timeBetweenEvictionRuns = timeBetweenEvictionRuns;
}
} }
/** /**
......
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -134,11 +134,14 @@ public class RedisAutoConfigurationJedisTests { ...@@ -134,11 +134,14 @@ public class RedisAutoConfigurationJedisTests {
@Test @Test
public void testRedisConfigurationWithPool() { public void testRedisConfigurationWithPool() {
this.contextRunner.withPropertyValues("spring.redis.host:foo", this.contextRunner
.withPropertyValues("spring.redis.host:foo",
"spring.redis.jedis.pool.min-idle:1", "spring.redis.jedis.pool.min-idle:1",
"spring.redis.jedis.pool.max-idle:4", "spring.redis.jedis.pool.max-idle:4",
"spring.redis.jedis.pool.max-active:16", "spring.redis.jedis.pool.max-active:16",
"spring.redis.jedis.pool.max-wait:2000").run((context) -> { "spring.redis.jedis.pool.max-wait:2000",
"spring.redis.jedis.pool.time-between-eviction-runs:30000")
.run((context) -> {
JedisConnectionFactory cf = context JedisConnectionFactory cf = context
.getBean(JedisConnectionFactory.class); .getBean(JedisConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo"); assertThat(cf.getHostName()).isEqualTo("foo");
...@@ -146,6 +149,8 @@ public class RedisAutoConfigurationJedisTests { ...@@ -146,6 +149,8 @@ public class RedisAutoConfigurationJedisTests {
assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4); assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4);
assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16); assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16);
assertThat(cf.getPoolConfig().getMaxWaitMillis()).isEqualTo(2000); assertThat(cf.getPoolConfig().getMaxWaitMillis()).isEqualTo(2000);
assertThat(cf.getPoolConfig().getTimeBetweenEvictionRunsMillis())
.isEqualTo(30000);
}); });
} }
......
...@@ -155,6 +155,7 @@ public class RedisAutoConfigurationTests { ...@@ -155,6 +155,7 @@ public class RedisAutoConfigurationTests {
"spring.redis.lettuce.pool.max-idle:4", "spring.redis.lettuce.pool.max-idle:4",
"spring.redis.lettuce.pool.max-active:16", "spring.redis.lettuce.pool.max-active:16",
"spring.redis.lettuce.pool.max-wait:2000", "spring.redis.lettuce.pool.max-wait:2000",
"spring.redis.lettuce.pool.time-between-eviction-runs:30000",
"spring.redis.lettuce.shutdown-timeout:1000").run((context) -> { "spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
LettuceConnectionFactory cf = context LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
...@@ -165,6 +166,8 @@ public class RedisAutoConfigurationTests { ...@@ -165,6 +166,8 @@ public class RedisAutoConfigurationTests {
assertThat(poolConfig.getMaxIdle()).isEqualTo(4); assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
assertThat(poolConfig.getMaxTotal()).isEqualTo(16); assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
assertThat(poolConfig.getMaxWaitMillis()).isEqualTo(2000); assertThat(poolConfig.getMaxWaitMillis()).isEqualTo(2000);
assertThat(poolConfig.getTimeBetweenEvictionRunsMillis())
.isEqualTo(30000);
assertThat(cf.getShutdownTimeout()).isEqualTo(1000); assertThat(cf.getShutdownTimeout()).isEqualTo(1000);
}); });
} }
......
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