ASP.Net Session State Provider Failover Scenario

948 Views Asked by At

We had implemented Redis session state provider to our web application and it works like a charm but i wonder what happens if redis server fails or web server couldn't connect to redis server.

Is there any way to use InProc Session State management as failover of Redis? I cannot find any documentation about declaring multiple session state providers so if redis fails, system can continue to work with using inproc. (I accept to lose session states in redis and start from scratch in case of fail and lose again session states inproc and start from scratch again if redis become available)

3

There are 3 best solutions below

7
pers On

You need to define slave for your redis-server and use redis sentinel to monitor your server

2
pers On

I'm using StackExchange library to connect to redis server.It's just a simple code which just shows how to subscribe to event and don't take it a final solution.Whenever sentinel chooses new server you will receive an event for that so you can select 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();
            }
        });
0
FireflyFeesh On

I have been having a similar issue with Redis failing as a backing for our session store and I can not find anything that allows for failover/failback to an other SessionStateProvider.

I was hoping there was something out there that would write to both Redis and SqlServer in mem table or similar and then read from 1, if fails read from 2. But, this does not seem to exist yet.