【发布时间】: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 感谢您的提示。这对我也有用。