2013-03-15 71 views
9

好吧,我覺得我錯過了一些關鍵信息。如何告訴客戶新的Redis主服務器使用Sentinel

本地我有1個主站和1個從Redis的服務器上的不同端口 http://redis.io/topics/sentinel

運行我也有3個哨兵,他們似乎都知道彼此的和預期工作。

現在我有一大堆java代碼指向127.0.0.1:6379,其中我的主redis服務器是。

如果我取下來的高手,定點確實寄託都如預期推動奴隸所以現在的新主人是

127.0.0.1:6380

我的問題是如何我的代碼知道這個掌握和自動切換?

回答

7

您必須在其pubsub頻道之一上訂閱哨兵消息。您可以在您發佈的哨兵會公佈出來的消息像

+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不聰明 - 你必須使用客戶端庫來處理這些事情。

具體而言,最有用的渠道

+odown 
+failover-detected 
+switch-master 
+0

什麼使用上Redis的主/從負載均衡。只有我有這個問題是我不能寫入到從正確的? – 2013-03-15 16:54:41

+0

你不想使用從機進行負載平衡。如果你想要負載平衡,你應該有多個節點在運行,並且在你的客戶端提出邏輯來處理哪些密鑰會進入哪個節點。 – 2013-03-15 18:00:03

+0

http://stackoverflow.com/questions/29210039/getting-redis-master-address-from-sentinel-c-sharp/29211741#29211741 – atikot 2015-03-23 14:02:50

相關問題