Azure Redis缓存StackExchange.Redis.RedisConnectionException:没有可用于此操作的连接:EVAL

时间:2015-12-09 13:10:36

标签: azure caching redis azure-caching azure-redis-cache

Asp.net mvc 5应用程序Web配置文件

   sessionState mode="Custom" customProvider="RedisSessionProvider">
      providers>
add name="RedisSessionProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" port="6380" host="XXX.redis.cache.windows.net" accessKey="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ssl="true" />
 providers>
    sessionState>

当我运行应用程序时有错误

Server Error in '/' Application.
No connection is available to service this operation: EVAL
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: EVAL
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[RedisConnectionException: No connection is available to service this operation: EVAL]
   StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl(Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:1922
   StackExchange.Redis.RedisBase.ExecuteSync(Message message, ResultProcessor`1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:80
   StackExchange.Redis.RedisDatabase.ScriptEvaluate(String script, RedisKey[] keys, RedisValue[] values, CommandFlags flags) in c:\TeamCity\buildAgent\work\3ae0647004edff78\StackExchange.Redis\StackExchange\Redis\RedisDatabase.cs:866
   Microsoft.Web.Redis.<>c__DisplayClass4.<Eval>b__3() in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:113
   Microsoft.Web.Redis.StackExchangeClientConnection.RetryForScriptNotFound(Func`1 redisOperation) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:129
   Microsoft.Web.Redis.StackExchangeClientConnection.RetryLogic(Func`1 redisOperation) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:155
   Microsoft.Web.Redis.StackExchangeClientConnection.Eval(String script, String[] keyArgs, Object[] valueArgs) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\Shared\StackExchangeClientConnection.cs:113
   Microsoft.Web.Redis.RedisConnectionWrapper.Set(ISessionStateItemCollection data, Int32 sessionTimeout) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisConnectionWrapper.cs:135
   Microsoft.Web.Redis.RedisSessionStateProvider.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) in c:\TeamCity\buildAgent\work\f55792526e6d9089\src\RedisSessionStateProvider\RedisSessionStateProvider.cs:408
   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +906
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

5 个答案:

答案 0 :(得分:2)

可能有三个原因:

  1. 你的连接字符串错误(看起来没问题)
  2. 该实例尚未创建(通常需要在azure中创建很多)
  3. 您正面临防火墙(包括Windows防火墙)问题
  4. 您是否可以使用命令提示符连接到redis缓存实例?

    下载redis for windows Here

    然后运行

    redis-cli -h XXX.redis.cache.windows.net -a XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 
    

    你可以在这里找到一个详细的演示(西班牙语,但控制台演示仍然可用。)

    NinjaTip #18 - Introducción a Redis

    出于测试目的,确保Redis服务已打开端口6379(这是您需要在azure上启用的非SSl端口选项)

    如果您无法连接到您的实例是因为上面列出了一些原因。

答案 1 :(得分:2)

之前我遇到过同样的问题,我找到了一个使用另一个问题的解决方案: https://github.com/alex-simonov/RedisAspNetProviders

这个适用于我

答案 2 :(得分:2)

我有相同的方法,最后通过在连接字符串中添加sslprotocols=tls12来解决它。没必要,但显然是,在Azure上使用最近创建的Redis缓存。可能是由于TLS 1.0和1.2弃用了

答案 3 :(得分:1)

我发现只有web配置中的以下配置对我有用:

<sessionState mode="Custom" customProvider="MySessionStateStore">
  <providers>
    <add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="PUTCORRECTNAMEHERE.edis.cache.windows.net:6380,password=YOURPRIMARYKEYPUTHERE,ssl=True,abortConnect=False" />
  </providers>
</sessionState>

答案 4 :(得分:0)

对我来说,这是一个防火墙问题。

在azure门户中,如下所示,我在防火墙部分下添加了我的IP地址,它对我有用。我给它起了“ allowme”的名字

azure redis firewall