简体   繁体   English

StackExchange.Redis 如何连接到 Sentinel

[英]StackExchange.Redis How to Connect to Sentinel

I want to get notificated when a master changes我想在 master 更改时收到通知

For this i wanted to connect to my sentinels but the connection Multiplexer tells me that the are not reachable.为此,我想连接到我的哨兵,但连接多路复用器告诉我无法访问。

What am I Doing wrong?我究竟做错了什么?

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

You can try the (much) newer version of StackExchange.Redis which comes with sentinel mode feature.您可以尝试使用带有哨兵模式功能的更新版本的 StackExchange.Redis。 You can now connect in sentinel mode with connection string like this:您现在可以使用如下连接字符串以哨兵模式进行连接:

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

It will auto-discover current master and return a managed connection which will handle the failover for you.它将自动发现当前主服务器并返回一个托管连接,该连接将为您处理故障转移。 If you want to be notified for master change you can subscribe the如果您想收到主更改通知,您可以订阅

    ConnectionMultiplexer.ConfigurationChanged

event.事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM