StackExchange.Redis 如何连接到 Sentinel

StackExchange.Redis How to Connect to Sentinel

我想在主人改变时得到通知

为此,我想连接到我的哨兵,但连接多路复用器告诉我它们无法访问。

我做错了什么?

 ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost:26380,localhost:26381,localhost:26382");

虽然有一些测试 (https://github.com/StackExchange/StackExchange.Redis/blob/master/StackExchange.Redis.Tests/Sentinel.cs),但我不确定是否实现了哨兵功能。您可以在这里签到:

https://github.com/StackExchange/StackExchange.Redis/issues/22

您可以尝试 StackExchange.Redis 的(更)新版本,它带有 sentinel mode 功能。您现在可以使用这样的连接字符串以哨兵模式连接:

    var conn = ConnectionMultiplexer.Connect("172.17.6.45:26379,serviceName=mymaster");

它将 auto-discover 当前主控和 return 一个将为您处理故障转移的托管连接。如果您想收到主更改通知,您可以订阅

    ConnectionMultiplexer.ConfigurationChanged

事件。