如何告诉客户端新Redis主服务器在哪里使用Sentinel [英] How to tell a Client where the new Redis master is using Sentinel

查看:97
本文介绍了如何告诉客户端新Redis主服务器在哪里使用Sentinel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我觉得我缺少一些重要的信息.

Ok, I feel like I'm missing some crucial piece of information.

我在本地有1个主服务器和1个从属Redis服务器在不同端口上运行 http://redis.io/topics/sentinel

Locally I have 1 master and 1 slave redis server running on different ports http://redis.io/topics/sentinel

我也有3个哨兵,他们似乎彼此了解,并按预期工作.

I also have 3 sentinels and they all appear to be aware of each other and working as expected.

现在,我有大量的Java代码指向我的主Redis服务器所在的127.0.0.1:6379.

Now I have a big of java code pointing to 127.0.0.1:6379 where my master redis server is.

如果我撤下了主服务器,哨兵将按预期的方式将奴隶提升为主服务器,因此现在新的主服务器已启用

If i take down the master, sentinel does everthing as expected promoting the slave to master so now the new master is on

127.0.0.1:6380

127.0.0.1:6380

我的问题是我的代码如何知道这一点并自动切换?

My question is how does my code know this and auto switch?

推荐答案

您必须在其pubsub频道之一上订阅哨兵消息.您可以在发布的链接中看到,哨兵将发布

You have to subscribe to sentinel messages on one of their pubsub channels. You can see at the link that you posted that the sentinel will publish out messages like

+odown <instance details> -- The specified instance is now in Objectively Down state.
-odown <instance details> -- The specified instance is no longer in Objectively Down state.
+failover-takedown <instance details> -- 25% of the configured failover timeout has elapsed, but this sentinel can't see any progress, and is the new leader. It starts to act as the new leader reconfiguring the remaining slaves to replicate with the new master.
+failover-triggered <instance details> -- We are starting a new failover as a the leader sentinel.

因此,当您看到在其中一个频道上发布了哨兵时,您需要解析消息并让您的客户端做出相应的响应.Redis并不聪明-您必须使用客户端库来处理这些事情.

So when you see a sentinel publish on one of those channels, you need to parse the message and have your client respond accordingly. Redis is not smart - you have to handle these things using a client library.

具体来说,最有用的渠道是

Specifically, the most useful channels are

+odown
+failover-detected
+switch-master

这篇关于如何告诉客户端新Redis主服务器在哪里使用Sentinel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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