Use Redis Service Instead of Asp.Net Session Provider
Asp.Net
Session Provider can’t realizeMaster-Slave
switching function, but the stable release ofRedis Sentinel
is shippedd sinceRedis 2.8
. Certainly, the sentinel function is supportMonitoring
,Notification
,Automatic failover
andConfiguration provider
.
If you want to know the extra information about
Redis Sentinel
, –> click here
Aspnet Redis Provider
Source Code
Go back to session provider, I found an solution in github, the open source see here
- If you just use redis make the session provider, this solution is completely instead of the Asp.Net session provider.
- But if you want
master-slave
switching or mutltiple instance used in redis master-slave swtiching, I fork the project and checkout a new branch, the code –> see here
BTW, How to install redis and redis sentinel please see here, And the detail
Redis Sentinel
configuration for windows please see here
Configuration for Application
PS. The sample
web.config
configuration forRedis Single
1 | <sessionState mode="Custom" customProvider="MySessionStateStore"> |
PS. The other sample
web.config
configuration forRedis Sentinel
1 | <connectionStrings> |
Question
Above this, I think a question about
redis master ip
when redis master instance is crash, how is it switched?
The answer in theRedis Sentinel
configuration, because I input the redis sentinelip
andport
in theweb config
, base on the quorum argument.
So, if I don’t change the source code, I can’t get the
master ip
when master instance crashed, but it’s other way to get the IP,Keepalived
, It will generate thevirtual IP
, and you can bind your redis instances ip, Ahha It’s only support on linux, so this solution is not suitable for me.
And the detail configuration and How to realize it, please see this article
Resources:
http://lib.csdn.net/article/redis/18114
Author: itabas016
Link: https://tech.itabas.com/2016/09/21/web/redis-service-instead-of-aspnet-session-provider/
License: CC BY-NC-ND 4.0