部署到服务器后无法连接到Azure Redis缓存

问题描述

some-prod.redis.cache.windows.net上的UnableToConnect:6380 /交互式,正在初始化/未启动,最后一个:无,来源:BeginConnectAsync,未完成:0,最后一次读取:5s之前,最后一次写入:5s之前,keep-alive:60s,状态:Connecting,mgr:10(共10)可用,last-heartbeat:never,global:5s前,v:2.1.58.34321 我正在尝试建立类似的连接

私有静态Lazy azureRedisCacheConnection = new Lazy(()=> { 返回ConnectionMultiplexer.Connect(AzureRedisCacheConfiguration.Instance.ConnectionString); });

    public static ConnectionMultiplexer RedisCacheConnection
    {
        get
        {
            return azureRedisCacheConnection.Value;
        }
    }

[RedisConnectionException: UnableToConnect on some-prod.redis.cache.windows.net:6380/Interactive,Initializing/NotStarted,last: NONE,origin: BeginConnectAsync,outstanding: 0,last-read: 5s ago,last-write: 5s ago,keep-alive: 60s,state: Connecting,mgr: 10 of 10 available,last-heartbeat: never,global: 5s ago,v: 2.1.58.34321]

[RedisConnectionException: No connection is active/available to service this operation: EVAL; UnableToConnect on Some.redis.cache.windows.net:6380/Interactive,v: 2.1.58.34321,mc: 1/1/0,clientName: INNOWIN134106,IOCP: (Busy=0,Free=1000,Min=8,Max=1000),WORKER: (Busy=1,Free=32766,Max=32767),v: 2.1.58.34321]
   StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl(Message message,ResultProcessor`1 processor,ServerEndPoint server) +394
   StackExchange.Redis.RedisBase.ExecuteSync(Message message,ServerEndPoint server) +166
   StackExchange.Redis.RedisDatabase.ScriptEvaluate(String script,RedisKey[] keys,RedisValue[] values,CommandFlags flags) +190
   Microsoft.Web.Redis.<>c__DisplayClass7_0.<Eval>b__0() in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\Shared\StackExchangeClientConnection.cs:68
   Microsoft.Web.Redis.StackExchangeClientConnection.OperationExecutor(Func`1 redisOperation) in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\Shared\StackExchangeClientConnection.cs:86
   Microsoft.Web.Redis.StackExchangeClientConnection.RetryLogic(Func`1 redisOperation) in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\Shared\StackExchangeClientConnection.cs:122
   Microsoft.Web.Redis.StackExchangeClientConnection.Eval(String script,String[] keyArgs,Object[] valueArgs) in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\Shared\StackExchangeClientConnection.cs:68
   Microsoft.Web.Redis.RedisConnectionWrapper.Set(ISessionStateItemCollection data,Int32 sessionTimeout) in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\RedisSessionStateProvider\RedisConnectionWrapper.cs:137
   Microsoft.Web.Redis.<SetAndReleaseItemExclusiveAsync>d__25.MoveNext() in C:\TeamCity\buildAgent\work\59b31e8e4035fd30\src\RedisSessionStateProvider\RedisSessionStateProvider.cs:433
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
   Microsoft.AspNet.SessionState.<ReleaseStateAsyncImpl>d__80.MoveNext() +809
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +68
   Microsoft.AspNet.SessionState.TaskAsyncHelper.EndTask(IAsyncResult ar) +58
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +510
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +213
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +172

解决方法

我认为也许connectionStrings应该附加,allowAdmin=true。那只是我的猜测。

常规,您应该在防火墙中添加规则。

enter image description here

故障排除。

您可以使用调试模型来部署Web应用程序,并可以使用远程调试来捕获错误。

您可以download my sample code in github。我的示例代码已经过测试,您可以尝试。

有关更多详细信息,您可以在另一篇文章中阅读我的答案。

How to reconnect redis client after redis server reboot/scale

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...