asp.netredissession-state-provider

Redis Session State Provider manage fallback


I use Redis as Session State Provider but since I have many users sometimes it happens that Redis goes down. So I would like to have a default Session State Provider to use in case the first one goes down.

Is this possible? Any other solutions?

Thanks


Solution

  • ASP.NET's session pipeline doesn't support falling back to a different session provider, so the fallback functionality would have to be baked into the Redis session state provider. But the Redis provider only talks to Redis, so you'd have to do this yourself, either in your own fork of the project or by creating your own custom session provider that inherits from SessionStateStoreProviderBase and wraps access to the RedisSessionStateProvider (along with whatever fallback storage logic you'd like to use if your provider detects a Redis outage).

    But you're looking a big fat mess now: where should you temporarily store the data (An in-process cache? Now you're talking sticky sessions. SQL Server? Yet another server to manage)... And, once Redis comes back up, how do you repopulate it with the active sessions from your temporary storage? There are lots of problems to think through, and it's no wonder that Microsoft doesn't support it.

    So your best bet, as @MatíasFidemraizer alluded to, is to focus your energy on improving your Redis deployment so that it can handle your load and also set up Master-Slave replication with Redis Sentinel to do automatic failover. If that's too much work then there are a number of commercial solutions that'll do the heavy lifting of failover for you (the company I work for has a dead-simple product called ScaleOut SessionServer)