ASP.Net Session State Provider Failover Scenario
Asked Answered
S

3

7

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)

Stine answered 13/4, 2015 at 6:45 Comment(0)
S
0

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

Strode answered 13/4, 2015 at 12:12 Comment(7)
So there is no way to configure alternative to redis like ASP.Net InProcStine
Check this ticket #15437834Strode
@alirezam I don't believe the ASP.NET Redis Session State Provider supports redis sentinels. If you know otherwise, I would be so VERY happy to be wrong.Aubarta
Sorry for my late response.You use sentinel for configuring your redis.In asp.net you subscribe to sentinel server and listen to the event whenver server changes and based on the new server you can update your webconfigStrode
Updating the web.config is not a good idea. Is there any other way?Chavis
Hi @bahadirarslan Is there any final solution/workaround for same, I am also facing the same problem and want to handle in MVC application.Minoru
Sorry @AshishShukla we couldn't find; also i left the job so i am not sure the last state. wish best luckStine
S
0

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.

Sardanapalus answered 24/3, 2020 at 9:29 Comment(0)
S
-1

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();
            }
        });
Strode answered 4/9, 2015 at 7:18 Comment(2)
Wouldn't you subscribe to "+switch-master" event? Also, your code does not exactly say how the switch is made in the application. Could you please elaborate the event handler?Chavis
You need to import libraries from StackExchange and use the code in global.asax fileStrode

© 2022 - 2024 — McMap. All rights reserved.