StackExchange.Redis 如何使用多个端点和连接? [英] How does StackExchange.Redis use multiple endpoints and connections?

查看:36
本文介绍了StackExchange.Redis 如何使用多个端点和连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如 StackExchange.Redis 基础文档中所述,您可以连接到多个 Redis服务器,并且 StackExchange.Redis 将自动确定主/从设置.引用相关部分:

As explained in the StackExchange.Redis Basics documentation, you can connect to multiple Redis servers, and StackExchange.Redis will automatically determine the master/slave setup. Quoting the relevant part:

更复杂的场景可能涉及主/从设置;对于这种用法,只需指定组成该逻辑 redis 层的所有所需节点(它将自动识别主节点):

A more complicated scenario might involve a master/slave setup; for this usage, simply specify all the desired nodes that make up that logical redis tier (it will automatically identify the master):

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("server1:6379,server2:6379");

我执行了一个测试,我触发了故障转移,这样主站会宕机一段时间,导致旧从站成为新主站,旧主站成为新从站.我注意到尽管有这种变化,StackExchange.Redis 一直在向旧的 master 发送命令,导致写操作失败.

I performed a test in which I triggered a failover, such that the master would go down for a bit, causing the old slave to become the new master, and the old master to become the new slave. I noticed that in spite of this change, StackExchange.Redis keeps sending commands to the old master, causing write operations to fail.

以上问题:

  1. StackExchange.Redis 如何决定使用哪个端点?
  2. 应该如何使用多个端点(如上例所示)?

我还注意到,对于每个连接,StackExchange.Redis 打开两个物理连接,其中一个是某种订阅.这究竟是用来做什么的?是否被 Sentinel 实例使用?

I also noticed that for each connect, StackExchange.Redis opens two physical connections, one of which is some sort of subscription. What is this used for exactly? Is it used by Sentinel instances?

推荐答案

应该发生的是,它使用许多东西(特别是定义的复制配置)来确定哪个是主服务器,并在适当的服务器上引导流量(尊重服务器"参数,默认为首选主服务器",但总是向主服务器发送写操作).

What should happen there is that it uses a number of things (in particular the defined replication configuration) to determine which is the master, and direct traffic at the appropriate server (respecting the "server" parameter, which defaults to "prefer master", but which always sends write operations to a master).

如果收到cannot write to a readonly slave"(我不记得确切的文本)错误,它将尝试重新建立配置,并且应该自动切换到尊重这.不幸的是,redis 不会广播配置更改,因此库无法提前检测到这一点.

If a "cannot write to a readonly slave" (I can't remember the exact text) error is received, it will try to re-establish the configuration, and should switch automatically to respect this. Unfortunately, redis does not broadcast configuration changes, so the library can't detect this ahead of time.

请注意,如果您使用库方法更改 master,它可以利用 pub/sub 来立即自动检测该更改.

Note that if you use the library methods to change master, it can exploit pub/sub to detect that change immediately and automatically.

关于第二个连接:那将用于发布/订阅;它会提前启动,因为默认情况下它会尝试侦听特定于库的配置广播.

Re the second connection: that would be for pub/sub; it spins this up ahead of time, as by default it attempts to listen for the library-specific configuration broadcasts.

这篇关于StackExchange.Redis 如何使用多个端点和连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆