amazon-elasticache - io.lettuce.core.RedisCommandTimeoutException : Command timed out

标签 amazon-elasticache redis-cluster lettuce

io.lettuce.core.RedisCommandTimeoutException: Command timed out after 10 second(s)
    at io.lettuce.core.ExceptionFactory.createTimeoutException(ExceptionFactory.java:51) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:114) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at io.lettuce.core.cluster.ClusterFutureSyncInvocationHandler.handleInvocation(ClusterFutureSyncInvocationHandler.java:123) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at com.sun.proxy.$Proxy72.get(Unknown Source) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor138.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212]
    at io.lettuce.core.support.ConnectionWrapping$DelegateCloseToConnectionInvocationHandler.handleInvocation(ConnectionWrapping.java:191) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80) ~[lettuce-core-5.1.6.RELEASE.jar:?]
    at com.sun.proxy.$Proxy72.get(Unknown Source) ~[?:?]

我正在使用以下示例代码通过连接池获取连接,请检查并建议我做错了什么
public StatefulRedisClusterConnection<String, String> getRedisClient() {
        log.debug("getRedisClient()");
        if (pool == null) {
            synchronized (this) {
                pool = initializeConnectionPool();
            }
        }
        try {
            return pool.borrowObject();
        } catch (Exception e) {
            log.error("getting pool connection failed",e);
        }
        return null;
    }

    public GenericObjectPool<StatefulRedisClusterConnection<String, String>> initializeConnectionPool() {
        RedisClusterClient clusterClient = RedisClusterClient.create(new RedisURI(clusterUrl, clusterPort,Duration.ofMillis(10000)));
        ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
                  .enableAllAdaptiveRefreshTriggers()
                  .refreshTriggersReconnectAttempts(30)
                  .build();
        clusterClient.setOptions(ClusterClientOptions.builder()
                .topologyRefreshOptions(topologyRefreshOptions)
                .build());
        pool = ConnectionPoolSupport.createGenericObjectPool(() -> clusterClient.connect(), getLettucePoolConfig());
        return pool;
    }

private GenericObjectPoolConfig getLettucePoolConfig() {
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxTotal(256);
        poolConfig.setBlockWhenExhausted(true);
        poolConfig.setMaxWaitMillis(10000);
        poolConfig.setMaxIdle(100);
        poolConfig.setMinIdle(50);
        poolConfig.setTestOnBorrow(false);
        poolConfig.setTestWhileIdle(true);
        return poolConfig;
    }

最佳答案

Redis 应该在毫秒内响应非常快,您也可以尝试从 application.yml 配置连接超时.

spring.redis.timeout: 5000
PS:这个值是测试用的,通常5秒对于Redis连接来说是一个很大的数字,另外检查你的应用是否可以访问Redis首先。
注意:你真的不需要那些 java 连接方法。 Spring Boot 开箱即用,几乎没有编码,这只是配置您的 application.yml 的问题
看:Spring Boot Configs for Redis

关于amazon-elasticache - io.lettuce.core.RedisCommandTimeoutException : Command timed out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57250297/

相关文章:

redis - 如何将RDB加载到redis集群

java - springboot redisTemplate 的拆箱。可能会产生 NullPointerException

redis - 使用 AWS Elasticache Redis 管理 Sails.js 中的 session

python - 如何在 Django 中设置 Memcached 检索超时

redis - 优化 Redis 集群节点

linux - Redis集群创建无法连接到服务器,怎么回事?

amazon-elastic-beanstalk - 弹性缓存卡在创建状态

amazon-web-services - 如何从 VPN 访问 AWS ElastiCache (Redis)

java - 如何将自己的执行器传递给redis lettuce库?

java - 如何在特定的spring boot版本中使用不同的spring模块(spring-data-redis)版本