jedis/lettuce timeout
Lettuce
When we use Lettuce, we don’t need to configure the RedisConnectionFactory. Spring Boot does it for us.
All we have left, then, is to specify a few properties in our application.properties file:
1 | spring.redis.database=0 |
jedis
- JedisConnectionFactory.setTimeout
ref: https://www.tabnine.com/code/java/methods/org.springframework.data.redis.connection.jedis.JedisConnectionFactory/setTimeout1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public RedisConnectionFactory factory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setDatabase(dateBase);
factory.setHostName(host);
factory.setPort(port);
factory.setPassword(password);
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxWaitMillis(maxWait);
poolConfig.setMaxTotal(maxTotal);
factory.setPoolConfig(poolConfig);
factory.setTimeout(timeout);
return factory;
}
JedisPool 优化
Parameter | Description | Default value | Recommended settings |
---|---|---|---|
maxTotal | The maximum number of connections that are supported by the pool. | 8 | For more information, see Recommended settings. |
maxIdle | The maximum number of idle connections in the pool. | 8 | For more information, see Recommended settings. |
minIdle | The minimum number of idle connections in the pool. | 0 | For more information, see Recommended settings. |
blockWhenExhausted | Specifies whether the client must wait when the resource pool is exhausted. Only when this parameter is set to true, the maxWaitMillis parameter takes effect. | true | We recommend that you use the default value. |
maxWaitMillis | The maximum number of milliseconds that the client must wait when no connection is available. | A value of -1 specifies that the connection never times out. | We recommend that you do not use the default value. |
testOnBorrow | Specifies whether to validate connections by using the PING command before the connections are borrowed from the pool. | Invalid connections are removed from the pool. | false |
testOnReturn | Specifies whether to validate connections by using the PING command before the connections are returned to the pool. | Invalid connections are removed from the pool. | false |
jmxEnabled | Specifies whether to enable Java Management Extensions (JMX) monitoring. | true | We recommend that you enable JMX monitoring. Take note that you must also enable the feature for your application. |