【发布时间】:2016-04-17 10:03:08
【问题描述】:
我是从nuget和StackExchange.Redis.StrongName安装XX的,也把下一个配置放到web.config RedisSessionStateProvider
<sessionState mode="Custom" customProvider="RedisSessionProvider" cookieless="true" > <providers> <add name="RedisSessionProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" port="6380" host="XXX.redis.cache.windows.net" accessKey="OQm………15E=" ssl="true" connectionTimeoutInMilliseconds="5000" operationTimeoutInMilliseconds="1000" retryTimeoutInMilliseconds="3000" writeExceptionsToEventLog="true" /></providers>
但无法将会话存储在redis上,但是如果我在代码上进行连接,则成功。我的代码:
/// 设置连接
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
var redisOption = new ConfigurationOptions();
return ConnectionMultiplexer.Connect("XXX.redis.cache.windows.net:6380,abortConnect=false,ssl=true,password=OQmAPmp0 . . . . TJE15E=");
});
///return connection object
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
///the session is created and added some elements manually in redis to test
public ActionResult SessionStart()
{
IDatabase cache = Connection.GetDatabase();
Session["loginTime"] = DateTime.Now.ToString();
string strValue = "myvalue";
Session.Add("myvalue ", strValue);
return View();
}
我需要在redis中自动存储会话,请帮帮我!
【问题讨论】:
-
你有没有得到任何错误?
-
只有会话值不能自动存储到redis缓存中
标签: c# asp.net-mvc redis session-state