【问题标题】:Cannot connect to Azure Redis after changing Minimum TLS version to 1.2将最低 TLS 版本更改为 1.2 后无法连接到 Azure Redis
【发布时间】:2020-02-07 11:57:10
【问题描述】:

在我的 .NET Framework 4.6.1 应用程序中,我使用 StackExchange.Redis.StrongName 1.2.6 连接到 Azure Redis。 这是代码

    public RedisContext(string connectionString = null)
    {
        if (connectionString == null) return;

        Lazy<ConfigurationOptions> lazyConfiguration
            = new Lazy<ConfigurationOptions>(() => ConfigurationOptions.Parse(connectionString));

        var configuration = lazyConfiguration.Value;
        configuration.SslProtocols = SslProtocols.Tls12;//just added
        configuration.AbortOnConnectFail = false;

        Lazy<ConnectionMultiplexer> lazyConnection =
            new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(configuration));
        _connectionMultiplexer = lazyConnection.Value;

        LogProvider.IsDisabled = true;

        var connectionEndpoints = _connectionMultiplexer.GetEndPoints();
        _lockFactory = new RedisLockFactory(connectionEndpoints.Select(endpoint => new RedisLockEndPoint
        {
            EndPoint = endpoint,
            Password = configuration.Password,
            Ssl = configuration.Ssl
        }));
    }

在 Azure 中,我已将 Redis 资源更改为使用 TLS1.2,并在代码中添加了这一行:

configuration.SslProtocols = SslProtocols.Tls12;//刚刚添加

现在,没有任何效果了。这是我在 Application Insights 中遇到的错误:

连接到 Redis 时出错。无法连接到 redis 服务器;连接超时

我也尝试在 redis 连接字符串中添加“,ssl=True,sslprotocols=tls12”,但结果相同。

【问题讨论】:

  • 添加,sslprotocols=tls12 是我所需要的。谢谢!
  • @itslittlejohn 感谢您的提示。这对我也有用。

标签: azure redis


【解决方案1】:

尝试引用 StackExchange.Redis 而不是 StackExchange.Redis.StrongName。我已经在我的一些项目中做到了这一点,现在它可以工作了。然而,一些第 3 方仍然使用 StrongName 而不是普通的 redis。 StackExchange.Redis.StrongName 现在已弃用。 https://github.com/Azure/aspnet-redis-providers/issues/107。我假设您正在尝试连接到 Azure Redis,因为它们停止了 TLS 1.0 和 1.1 支持?

【讨论】:

  • 是的,我们需要 Azure Redis 的 TLS 1.2。我将尝试看看它在 StackExchange.Redis 中的表现。
  • 升级到最新版本的 RedLock 和 StackExchange.Redis 后工作
猜你喜欢
  • 2020-10-28
  • 2018-11-10
  • 2020-06-22
  • 2018-10-28
  • 2020-06-04
  • 1970-01-01
  • 2021-06-03
  • 2015-12-05
  • 1970-01-01
相关资源
最近更新 更多