在我的 .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 服务器;连接超时
我还尝试将“,ssl=True,sslprotocols=tls12”添加到redis连接字符串中,但结果相同。
最佳答案
尝试引用 StackExchange.Redis 而不是 StackExchange.Redis.StrongName。我已经在我的一些项目中做到了这一点,现在它可以工作了。然而,一些第三方仍然使用 StrongName 而不是普通的 redis。 StackExchange.Redis.StrongName 现已弃用。 https://github.com/Azure/aspnet-redis-providers/issues/107 。我假设您尝试连接到 Azure Redis 与它们停止 TLS 1.0 和 1.1 支持有关?
关于azure - 将最低 TLS 版本更改为 1.2 后无法连接到 Azure Redis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60113048/