我永远无法将字符串值存储到Azure托管的Redis缓存中。使用StackExchange.Redis版本2.0.601以及vs2015和vs2019。下面的代码在注释中有错误(基本上即使成功使用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:(忙= 0,空闲= 1000,最小值= 4,最大值= 1000),工作人员:(忙= 2,空闲= 1021,最小值= 4,最大值= 1023),本地CPU:不适用

最佳答案

当我在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

    关于azure - 使用StackExchange.Redis存储到Azure托管Redis缓存时出现问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60348287/

    10-16 21:37