1.我在这里直接用 cachemanager.redis 往redis里面存储缓存数据
2.步骤
1)下载CacheManager.Redis(包含了CacheManager.Core)
下载StackExchange.Redis(c# redis的客户端交互的工具)
RedisSessionProvider (redis Session 保存驱动)
为了查看Redis方便我还特意的下了一个redis的GUI(RedisDesktopManager https://github.com/uglide/RedisDesktopManager)
代码在application_start:
string RedisServer = string.Format("{0}:{1}", "127.0.0.1", ""); //配置session保存到redis
ConfigurationOptions redisConfigOpts = ConfigurationOptions.Parse(RedisServer);
RedisConnectionConfig.GetSERedisServerConfig = (HttpContextBase context) =>
{
return new KeyValuePair<string, ConfigurationOptions>(
"DefaultConnection",
redisConfigOpts);
}; //RedisHelper redis = RedisHelper.Instance;
//redis.Init(RedisServer); CacheHelper.Init("Citms.Cache", RedisServer);
web.config
<sessionState mode="Custom" cookieless="false" timeout="30" customProvider="RedisSessionProvider">
<providers>
<add name="RedisSessionProvider" type="RedisSessionProvider.RedisSessionStateStoreProvider, RedisSessionProvider" />
</providers>
</sessionState>
这样session就存到了redis里面