使用RedisAdvancedClusterCommands get(key)时获取RedisCommandTimeoutException

时间:2019-08-06 14:22:47

标签: spring-boot redis lettuce

我正在使用生菜版本5.1.3.RELEASE。现在,当使用RedisAdvancedClusterCommands hmgetAll时,它可以正常工作,但是当使用GET方法时,它始终返回ReddisCommandTimeoutException。请帮助我我做错了什么地方。

得到问题,在使用异步并在同一连接上执行hgetAll的过程中,我正在使用同步,然后给出超时,否则不调用hgetAll即可正常工作。

我还使用RedisAdvancedClusterAsyncCommands来度过未来,然后又超时。也将超时时间增加到50秒,这也快到了,但是群集结束正常运行。

用于连接

private GenericObjectPool<StatefulRedisClusterConnection<String, String>> pool;

ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder()
                .enablePeriodicRefresh(Duration.ofHours(1))
                .enableAllAdaptiveRefreshTriggers()
                .build();
            ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder()
                .topologyRefreshOptions(clusterTopologyRefreshOptions)
                .validateClusterNodeMembership(false)
                .autoReconnect(true)
                .build();
            redisClusterClient = RedisClusterClient.create("redis://" + redisUrl);
            redisClusterClient.setOptions(clusterClientOptions);
            redisClusterClient.setDefaultTimeout(Duration.ofMillis(5000));
            GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
            poolConfig.setMaxTotal(100);
            poolConfig.setMaxIdle(100);
            poolConfig.setMinIdle(75);
            pool = ConnectionPoolSupport.createGenericObjectPool(() -> {
                StatefulRedisClusterConnection<String, String> connection = redisClusterClient.connect();
                connection.setReadFrom(ReadFrom.valueOf("NEAREST"));
                return connection;
            }, poolConfig);

获取数据

 @Override
    public String get(String key) {
        try (StatefulRedisClusterConnection<String, String> connection = getConnection()) {
            RedisAdvancedClusterCommands<String, String> pipeline = connection.sync();
            key = keyWithNamespace(key);
            return pipeline.get(key);
        } catch (Exception e) {
            logger.error("Redis exception in get: " + e);
        }
        return null;
    }

获得连接

 private StatefulRedisClusterConnection<String, String> getConnection() throws Exception {
        return pool.borrowObject();
    }

我在get中得到Redis异常:io.lettuce.core.RedisCommandTimeoutException:命令在5秒后超时

0 个答案:

没有答案