I am using the StackExchange library to connect to the redis server. This is just simple code that simply shows how to subscribe to an event and not make its final decision. If any controller selects a new server, you will receive an event for this so you can select a new server.
ConnectionMultiplexer multiplexer = ConnectionMultiplexer.Connect(new ConfigurationOptions { CommandMap = CommandMap.Sentinel, EndPoints = { { "127.0.0.1", 26379 }, { "127.0.0.1", 26380 } }, AllowAdmin = true, TieBreaker = "", ServiceName = "mymaster", SyncTimeout = 5000 }); multiplexer.GetSubscriber().Subscribe("*", (c, m) => { Debug.WriteLine("the message=" + m); Debug.WriteLine("channel=" + c); try { var sentinelServer = multiplexer.GetServer("127.0.0.1", 26379).SentinelGetMasterAddressByName("mymaster"); Debug.WriteLine("Current server=" + sentinelServer); Debug.Flush(); } catch (Exception) { var sentinelServer = multiplexer.GetServer("127.0.0.1", 26380).SentinelGetMasterAddressByName("mymaster"); Debug.WriteLine("Current server=" + sentinelServer ); Debug.Flush(); } });
source share