首页 > 解决方案 > Redis java.util.NoSuchElementException:池耗尽

问题描述

java.util.concurrent.ExecutionException: java.util.NoSuchElementException: Pool exhausted - Unable to get key(xxx), Exception: java.util.NoSuchElementException: Pool exhausted

当我尝试使用从集群 Redis 获取密钥时出现此错误BoundedAsyncPool

private Integer maxTotal = 20;
private Integer maxIdle  = 20;
private Integer minIdle = 10 ;

这是我的代码:

@Override
public Object get(String key, Class<?> clazz) {
    CompletableFuture<String> getResult = pool.acquire().thenCompose(connection -> {
        connection.setReadFrom(ReadFrom.REPLICA);
        RedisAdvancedClusterAsyncCommands<String, String> async = connection.async();
        return async.get(key).whenComplete((s, throwable) -> pool.release(connection));
    });
    try {
        String value = getResult.get();
        if (StringUtils.isEmpty(value)) {
            return null;
        }
        return new ObjectMapper().readValue(value, clazz);
    } catch (Exception e) {
        LOG.error(e, String.format("Unable to get key(%s), Exception: %s", key, e.getMessage()));
    }
    return null;
}

标签: javaspring-bootredisredis-cluster

解决方案


推荐阅读