Merge pull request #9526 from mp911de:set-lettuce-shutdown-timeout-properly
* pr/9526: Polish "Set Lettuce shutdown timeout properly" Reduce Lettuce shutdown timeout to 100ms Set Lettuce shutdown timeout properly
This commit is contained in:
commit
865971a540
|
@ -85,8 +85,16 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
|||
|
||||
private LettuceConnectionFactory createLettuceConnectionFactory(
|
||||
ClientResources clientResources) {
|
||||
return new LettuceConnectionFactory(applyProperties(createLettucePool(),
|
||||
this.properties.getLettuce().getPool(), clientResources));
|
||||
return applyProperties(
|
||||
new LettuceConnectionFactory(applyProperties(createLettucePool(),
|
||||
this.properties.getLettuce().getPool(), clientResources)));
|
||||
}
|
||||
|
||||
private LettuceConnectionFactory applyProperties(
|
||||
LettuceConnectionFactory connectionFactory) {
|
||||
connectionFactory
|
||||
.setShutdownTimeout(this.properties.getLettuce().getShutdownTimeout());
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
private DefaultLettucePool createLettucePool() {
|
||||
|
@ -173,7 +181,7 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
|||
RedisProperties.Lettuce lettuce = this.properties.getLettuce();
|
||||
if (lettuce.getShutdownTimeout() >= 0) {
|
||||
builder.shutdownTimeout(Duration
|
||||
.ofSeconds(this.properties.getLettuce().getShutdownTimeout()));
|
||||
.ofMillis(this.properties.getLettuce().getShutdownTimeout()));
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
|
|
|
@ -316,7 +316,7 @@ public class RedisProperties {
|
|||
/**
|
||||
* Shutdown timeout in milliseconds.
|
||||
*/
|
||||
private int shutdownTimeout = 2000;
|
||||
private int shutdownTimeout = 100;
|
||||
|
||||
/**
|
||||
* Lettuce pool configuration.
|
||||
|
|
|
@ -72,13 +72,15 @@ public class RedisAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testOverrideRedisConfiguration() {
|
||||
load("spring.redis.host:foo", "spring.redis.database:1");
|
||||
load("spring.redis.host:foo", "spring.redis.database:1",
|
||||
"spring.redis.lettuce.shutdown-timeout:500");
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(cf.getDatabase()).isEqualTo(1);
|
||||
assertThat(cf.getPassword()).isNull();
|
||||
assertThat(cf.isUseSsl()).isFalse();
|
||||
assertThat(cf.getShutdownTimeout()).isEqualTo(500);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -118,7 +120,8 @@ public class RedisAutoConfigurationTests {
|
|||
load("spring.redis.host:foo", "spring.redis.lettuce.pool.min-idle:1",
|
||||
"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.max-wait:2000",
|
||||
"spring.redis.lettuce.shutdown-timeout:1000");
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(getDefaultLettucePool(cf).getHostName()).isEqualTo("foo");
|
||||
|
@ -127,6 +130,7 @@ public class RedisAutoConfigurationTests {
|
|||
assertThat(getDefaultLettucePool(cf).getPoolConfig().getMaxTotal()).isEqualTo(16);
|
||||
assertThat(getDefaultLettucePool(cf).getPoolConfig().getMaxWaitMillis())
|
||||
.isEqualTo(2000);
|
||||
assertThat(cf.getShutdownTimeout()).isEqualTo(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -886,7 +886,7 @@ content into your application; rather pick only the properties that you need.
|
|||
spring.redis.lettuce.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
|
||||
spring.redis.lettuce.pool.max-wait=-1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
|
||||
spring.redis.lettuce.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
|
||||
spring.redis.lettuce.shutdown-timeout=2000 # Shutdown timeout in milliseconds.
|
||||
spring.redis.lettuce.shutdown-timeout=100 # Shutdown timeout in milliseconds.
|
||||
spring.redis.password= # Login password of the redis server.
|
||||
spring.redis.port=6379 # Redis server port.
|
||||
spring.redis.sentinel.master= # Name of Redis server.
|
||||
|
|
Loading…
Reference in New Issue