【问题标题】:Redis Cache - A blocking operation was interrupted by a call to WSACancelBlockingCallRedis 缓存 - 调用 WSACancelBlockingCall 中断了阻塞操作
【发布时间】:2021-02-03 14:13:06
【问题描述】:

我有一个带有以下代码的 ASP.NET Web 表单页面:

public partial class MyAspNetWebFormPage : System.Web.UI.Page{
   protected void Page_Load(object sender, EventArgs e){
      ClearRedisCache("RedisCacheConnectionString_01");
      ClearRedisCache("RedisCacheConnectionString_02");
   }

   private void ClearRedisCache(string redisConnectionString){
      var serverName = redisConnectionString.Split(',')[0];
      using (var redis = ConnectionMultiplexer.Connect(redisConnectionString)){
         var server = redis.GetServer(serverName);
         server.FlushAllDatabases(CommandFlags.None);
         redis.Close(true); // this was added as an effort to fix the problem but doesn't work
         
         // Another effort to make it work
         // Added after receiving the error
         do {
            Thread.Sleep(1000);
         } while (redis.IsConnected);
      }
   }
}

当我在本地机器上运行它时,它似乎工作得非常好。但是,当我在我们的 Azure 环境中运行它时,它会引发异常并显示以下消息:

阻塞操作被 WSACancelBlockingCall 调用中断

我见过的其他示例是缓存连接并保持打开状态。这就是我想实现redis缓存的方式吗?

此代码从与消费者站点完全断开的管理仪表板执行。 Admin Dashboard 不使用 Redis 缓存,只是清除它。

非常感谢任何想法。提前谢谢你。

【问题讨论】:

  • 您解决了这个错误吗?
  • @zalenix - 请参阅下面的答案。

标签: c# asp.net .net azure redis


【解决方案1】:

进一步研究并使用以下设置对我有用:

public partial class MyAspNetWebFormPage : System.Web.UI.Page{
   protected void Page_Load(object sender, EventArgs e){
      ClearRedisCache("RedisCacheConnectionString_01");
      ClearRedisCache("RedisCacheConnectionString_02");
   }

   private void ClearRedisCache(string redisConnectionString){
      string securityProtocol = (SecurityProtocol)Enum.Parse(typeof(SecurityProtocol), securityProtocol);

      var options = ConfigurationOptions.Parse(redisConnectionString);
      options.SslProtocols = System.Security.authentication.SslProtocols.Tls12;
      options.Ssl = true;
      options.AllowAdmin = true;
      options.AbortOnConnectFail = false;

      var serverName = redisConnectionString.Split(',')[0];
      using (var redis = ConnectionMultiplexer.Connect(options)){
         var server = redis.GetServer(serverName);
         server.FlushAllDatabases(CommandFlags.None);
      }
   }
}

【讨论】:

  • 感谢您的回答!我也检查了一下,是 sslprotocols = tls12 设置使它工作。
猜你喜欢
  • 1970-01-01
  • 2014-07-22
  • 2013-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-21
  • 2020-06-29
相关资源
最近更新 更多