I am using redis
in pubsub
model with following code
@Value("${redis.server.host}")
private String redisServerHost;
@Value("${redis.server.port}")
private int redisServerPort;
@Value("${redis.server.password}")
private String redisServerPassword;
@Value("${redis.pool.min.idle}")
private int poolMinIdle;
@Value("${redis.pool.max.idle}")
private int poolMaxIdle;
@Value("${redis.pool.max.total}")
private int poolMaxTotal;
@Value("${redis.pool.max.waitmilli}")
private int poolMaxWait;
@Value("${redis.pool.connection.name}")
private String connectionName;
@Value("${redis.pool.max.evictable}")
private int poolMaxEvictable;
@Bean
RedisConnectionFactory connectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisServerHost,
redisServerPort);
if ((redisServerPassword != null) && (!redisServerPassword.equalsIgnoreCase("null"))) {
redisStandaloneConfiguration.setPassword(RedisPassword.of(redisServerPassword));
}
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(poolMaxIdle);
poolConfig.setMinIdle(poolMinIdle);
poolConfig.setMaxWaitMillis(poolMaxWait);
poolConfig.setMaxTotal(poolMaxTotal);
poolConfig.setMinEvictableIdleTimeMillis(poolMaxEvictable);
LettucePoolingClientConfiguration lettucePoolingClientConfiguration = LettucePoolingClientConfiguration
.builder().clientName(connectionName).commandTimeout(Duration.ofSeconds(10))
.shutdownTimeout(Duration.ZERO).poolConfig(poolConfig).build();
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration,
lettucePoolingClientConfiguration);
lettuceConnectionFactory.setShareNativeConnection(false);
return lettuceConnectionFactory;
}
where
minIdle = 10
maxIdle = 50
maxTotal = 200
evictableTime = 20000
maxWait = 2000
Still I am getting issues of org.springframework.data.redis.RedisSystemException: Unknown redis exception; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is java.util.NoSuchElementException: Timeout waiting for idle object
After checking client list
I can see it has 200 clients already been created, though at a time my application is not creating these many connections.
Client list has major portion of clients with cmd=client
and 4-5 publisher/subscriber
Any direction please to resolve the issue.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…