【问题标题】:ioredis - ClusterAllFailedError: Failed to refresh slots cacheioredis - ClusterAllFailedError:刷新插槽缓存失败
【发布时间】:2019-12-12 12:38:29
【问题描述】:

我正在处理来自 ioredis 和 Elasticache 的 ClusterAllFailedError: Failed to refresh slots cache. 问题。这是我的集群配置

const clusterOptions = {
    enableReadyCheck: true,
    retryDelayOnClusterDown: 300,
    retryDelayOnFailover: 1000,
    retryDelayOnTryAgain: 3000,
    slotsRefreshTimeout: 200000000000000,
    clusterRetryStrategy: (times) => Math.min(times * 1000, 10000),
    dnsLookup: (address, callback) => callback(null, address),
    scaleReads: 'slave',
    showFriendlyErrorStack: true,
    redisOptions: {
        keyPrefix: config.queue.prefix,
        autoResubscribe: true,
        autoResendUnfulfilledCommands: true
    }
}

const redisClientInstance = new Redis.Cluster([{ host: '', port: ''}], clusterOptions);

但尝试访问 Redis 总是会导致 Failed refresh slots cache。其他人处理过这个问题吗?

谢谢。

【问题讨论】:

    标签: node.js amazon-web-services redis amazon-elasticache


    【解决方案1】:

    以下对我有用。

    Redis 版本AWS ElastiCache 上的 5.0.4 启用了 TLSAUTH 的集群。

    ioredis 版本4.16.0

    连接代码:

    const redis = new Redis.Cluster(
                [{ "host": <ELASTI_CACHE_CONFIGURATION_ENDPOINT> }], {
                    dnsLookup: (address, callback) => callback(null, address),
                    redisOptions: {
                        tls: true,
                        password: <ELASTI_CACHE_REDIS_AUTH>
                    }
                });
    

    当您启动ElastiCache 时,您需要指定一个或多个Subnet Group(通常是私有子网)和Security Group。当您从任何计算(Lambda、EC2 等)运行上述代码时,您需要确保以下内容

    • ElastiCache 可从您的 Compute 访问(将计算放在可以与 ElastiCache 的子网通信的子网中,在同一个 VPC 中。如果计算和 Elasticache 在不同的 VPC 上,请确保在他们。)
    • 确保Security GroupNACL 允许从您的计算Subnet 连接到ElastiCache 端口(@98​​7654335@ 是默认值)
    • 最后确保计算可以采用IAM Role(EC2 实例配置文件、Lambda 角色等),它具有对ElastiCache 的适当访问权限。如果您在 EC2 实例上运行,请确保您的代码使用在 EC2 实例配置文件中分配的角色的临时凭证。

    【讨论】:

    • 什么是正确的 VPC、子网、安全组?
    • @VinitKhandelwal 更新了有关正确 VPC、子网、SG 等的更多详细信息。强烈建议阅读文档。
    • 我试过你的解决方案,但过了一段时间,它抛出错误'ClusterAllFailedError: Failed to refresh slots cache'
    • 遗憾的是,这仍然返回 [ioredis] Unhandled 错误事件:ClusterAllFailedError: Failed to refresh slots cache, for redis engine 6.2.5 and 4.16.0 of ioredis
    【解决方案2】:

    这对我有用,但是我在打字稿中使用它时遇到了小问题,在将 null 传递给回调函数的第一个参数时遇到了问题,该函数期望 NodeJS.ErrnoException 并且不想允许使用任何类型(由于 eslint @ 987654322@规则)。

    我在 dnsLookup 上面使用了@ts-expect-error 指令

        // @ts-expect-error this will ignore error
        dnsLookup: (address, callback) => callback(null, address),
    

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多