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)

bahadir arslan
  • 4,535
  • 7
  • 44
  • 82

3 Answers3

0

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

pers
  • 195
  • 12
  • So there is no way to configure alternative to redis like ASP.Net InProc – bahadir arslan Apr 13 '15 at 14:25
  • Check this ticket http://stackoverflow.com/questions/15437334/how-to-tell-a-client-where-the-new-redis-master-is-using-sentinel – pers Apr 14 '15 at 08:02
  • 2
    @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. – Hovis Biddle Aug 26 '15 at 22:16
  • 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 webconfig – pers Sep 04 '15 at 07:06
  • Updating the web.config is not a good idea. Is there any other way? – Tom May 04 '16 at 20:28
  • Hi @bahadirarslan Is there any final solution/workaround for same, I am also facing the same problem and want to handle in MVC application. – Ashish Shukla Nov 21 '17 at 03:15
  • Sorry @AshishShukla we couldn't find; also i left the job so i am not sure the last state. wish best luck – bahadir arslan Nov 22 '17 at 09:21
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.

-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();
            }
        });
pers
  • 195
  • 12
  • 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? – Tom May 04 '16 at 20:22
  • You need to import libraries from StackExchange and use the code in global.asax file – pers Sep 29 '17 at 18:25