ASP.Net Session Provider Failover Scenario

We have implemented a Redis session state provider for our web application, and it works like a charm, but I am wondering what will happen if the redis server fails or the web server cannot connect to the redis server.

Can I use InProc session state management as recovery from Redis? I cannot find documentation on declaring multiple session state providers, so if redis fails, the system can continue to work using inproc. (I agree to lose session states in redis and start from scratch in the event of a failure and lose the inproc session states again and start from scratch again if redis becomes available)

+6
source share
2 answers

You need to define a subordinate for your redis server and use redis sentinel to monitor your server.

0
source

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(); } }); 
-1
source

Source: https://habr.com/ru/post/985041/


All Articles