Redis缓存-对WSACancelBlockingCall的调用中断了阻塞操作



我有一个ASP.NET Web Forms页面,其中包含以下代码:

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缓存的方式吗?

此代码是在与消费者网站完全断开连接的管理面板上执行的。管理面板不使用Redis缓存,只是清除它。

任何想法都将不胜感激。提前谢谢。

深入研究并使用设置,以下是对我有效的方法:

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);
}
}
}

最新更新