【问题标题】:Problem using StackExchange.Redis to store to Azure hosted redis cache使用 StackExchange.Redis 存储到 Azure 托管的 redis 缓存时出现问题
【发布时间】:2020-06-06 10:51:12
【问题描述】:

我永远无法将字符串值存储到 Azure 托管的 Redis 缓存。使用 StackExchange.Redis 版本 2.0.601 和 vs2015 和 vs2019。下面的代码在 cmets 中有错误(基本上即使 ConnectionMultiplexer.Connect 成功,也没有建立连接)。

    static bool Connect()
    {           
        ConnectionMultiplexer redis; 

        try
        {
            ConfigurationOptions cfgOptions = new ConfigurationOptions
            {
                EndPoints =
                {
                    {"RedisOnMyAzureServer", myPort}
                },
                AbortOnConnectFail = false,
                Ssl = true,
                ConnectRetry = 3,
                ConnectTimeout = 10000,
                SyncTimeout = 10000,
                DefaultDatabase = 0,
                Password = "myPassword"
            };
            redis = ConnectionMultiplexer.Connect(cfgOptions);   // takes 10.5 seconds on average 
        }
        catch
        { return false; }  // never errors

        // some diagnostics follow

        if (redis.IsConnected) 
            Console.WriteLine("client connection open"); 
        else
            Console.WriteLine("client connection closed");

        if (redis.GetDatabase().IsConnected(default(RedisKey))) 
            Console.WriteLine("database connection open"); 
        else 
            Console.WriteLine("database connection closed");

        // both connection are always closed.

        try
        {
            IDatabase db = redis.GetDatabase();
            db.StringSet("mykey", "value");
        }
        catch
        { return false; }  // always errors 

        return true;
    }

db.StringSet 方法的最后尝试/捕获错误。我收到这条消息:

没有可用的连接来服务这个操作:SET mykey;调用 WSACancelBlockingCall 中断了阻塞操作; IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=2,Free=1021,Min=4,Max=1023), Local-CPU: n/a

【问题讨论】:

  • 请编辑您的问题并包含错误详细信息。
  • 嗨 Gaurav。我添加了发生在 db.StringSet("mykey", "value"); 的错误。谢谢
  • AbortOnConnectFail = false 将使 SDK 忽略 ConnectionMultiplexer.Connect 中的错误。这就是为什么您只看到 StringSet 的原因。我的猜测是您在通往 VM 的途中遇到了网络问题。如果您使用的是 Azure Redis 缓存 (SaaS),则不应使用 Endpoint/Server/Password,而应尝试使用连接字符串。 ConnectionMultiplexer.Connect(RedisCacheConnectionString)

标签: azure redis stackexchange.redis


【解决方案1】:

当我在 Azure Redis 缓存上将最低 TLS 版本设置为 1.2 时,我遇到了同样的错误,这是由 TLS 不匹配引起的。通过以下措施解决。

  • 在连接字符串中添加sslprotocols=tls12
  • TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 添加到 TLS 密码套件

这里是详细信息,Remove TLS 1.0 and 1.1 from use with Azure Cache for Redis

【讨论】:

  • 在 web.config 中添加了上面的键并且它起作用了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 2014-10-05
  • 2019-04-15
相关资源
最近更新 更多