【问题标题】:Why is read replica on Elasticache Redis instance not showing handling any read requests?为什么 Elasticache Redis 实例上的只读副本未显示处理任何读取请求?
【发布时间】:2020-05-29 09:09:49
【问题描述】:

我有一个带有 2 个节点的 AWS Elasticache Redis 实例 - 主节点和只读副本。我正在使用StackExchange.Redis 连接到实例。

传递给构造函数的databases 值是一个逗号分隔的字符串,包含主端点和读取器端点。

public class RedisCacheConnectionFactory : IRedisCacheConnectionFactory
{
    private readonly Lazy<ConnectionMultiplexer> _connector;

    public RedisCacheConnectionFactory(string databases)
    {
        var options = ConfigurationOptions.Parse(databases);
        options.AbortOnConnectFail = false;
        options.SyncTimeout = 1000;
        this._connector = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(options));
    }

    public ConnectionMultiplexer Connection() => this._connector.Value;
}

看起来没有读取请求会发送到只读副本,并且它们都在访问主实例。

我的印象是只读副本有助于分担读取请求的负载以提高吞吐量。为什么没有针对只读副本显示读取请求?

【问题讨论】:

  • 你找到答案了吗??

标签: redis stackexchange.redis amazon-elasticache


【解决方案1】:

Redis 命令有一个标志,可让您控制副本的使用。默认实现更喜欢 Master。您需要将可选的CommandFlags 参数显式指定为CommandFlags.PreferSlaveCommandFlags.PreferReplica(看起来它们都设置为相同的值)。

请看这里:https://github.com/StackExchange/StackExchange.Redis/issues/1363#issuecomment-590592408

https://github.com/StackExchange/StackExchange.Redis/blob/8612fb8a9278822c87d5476819325a7438e596ca/src/StackExchange.Redis/Enums/CommandFlags.cs#L47

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2015-07-12
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多