gpt4 book ai didi

azure - 将 AbortOnConnectFail 设置为 false 后,我们仍然会在 Azure REDIS 上收到 ConnectTimeout

转载 作者:行者123 更新时间:2023-12-02 06:01:15 26 4
gpt4 key购买 nike

我们在 .NET Core 2.0 Azure 应用服务中偶然收到以下错误日志:

StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: GET post:307948:media;
It was not possible to connect to the redis server(s).
To create a disconnected multiplexer, disable AbortOnConnectFail.
ConnectTimeout; IOCP: (Busy=0,Free=1000,Min=4,Max=1000),
WORKER: (Busy=20,Free=662,Min=4,Max=682),
Local-CPU: n/a ---> System.AggregateException: One or more errors occurred.
(It was not possible to connect to the redis server(s).
To create a disconnected multiplexer, disable AbortOnConnectFail. ConnectTimeout)
(UnableToConnect on api-prod.redis.cache.windows.net:6380/Interactive,
Initializing, last: NONE,
origin: BeginConnectAsync, outstanding: 0, last-read: 12s ago, last-write: 12s ago,
unanswered-write: 290293s ago, keep-alive: 60s,
state: Connecting, mgr: 10 of 10 available,
last-heartbeat: never, global: 0s ago, v: 2.0.513.63329)

我找到的所有答案和博客文章都告诉我们将属性 AbortOnConnectFail 设置为 false。我们已经将此属性设置为 false,但仍然会出现这些错误。这是我们的实现:

public class CacheService : ICacheService
{
private static IRedisConfiguration _redisConfiguration;
private readonly IDateService _dateService;

private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
new Lazy<ConnectionMultiplexer>(() =>
{
var configurationOptions = CreateConfigurationOptions();
return ConnectionMultiplexer.Connect(configurationOptions);
});

public CacheService(IRedisConfiguration redisConfiguration, IDateService dateService)
{
_redisConfiguration = redisConfiguration;
_dateService = dateService;
}

private static ConfigurationOptions CreateConfigurationOptions()
{
var deltaBackOffInMilliseconds = TimeSpan.FromSeconds(5).Milliseconds;
var maxDeltaBackOffInMilliseconds = TimeSpan.FromSeconds(20).Milliseconds;

var config = new ConfigurationOptions();

//https://learn.microsoft.com/en-us/azure/architecture/best-practices/retry-service-specific#azure-redis-cache-retry-guidelines
config.AbortOnConnectFail = false;
config.ConnectRetry = 3;
config.ConnectTimeout = 2000;
config.ReconnectRetryPolicy = new ExponentialRetry(deltaBackOffInMilliseconds, maxDeltaBackOffInMilliseconds);

config.EndPoints.Add(_redisConfiguration.HostName);
config.Password = _redisConfiguration.Password;
config.Ssl = _redisConfiguration.Ssl;
config.DefaultDatabase = _redisConfiguration.DatabaseId;

return config;
}

public static ConnectionMultiplexer Connection => LazyConnection.Value;

public static IDatabase Cache => Connection.GetDatabase();
}

在 Azure 应用服务上,我检查了 TCP 连接,没有显示任何警告。 传出连接有所增加,但低于 1000。

运行两个 API 实例时,我们有大约 80 个连接,几乎保持不变。当天没有增加,因此连接管理似乎是正确的。

关于如何解决这个问题有什么建议吗?也许这是由于更多的配置调整。

Azure Redis:P1 高级层StackExchange.Redis 版本:2.0.513在 .NET Core 2.0 上运行的 .NET Core API

提前非常感谢。

最佳答案

我不知道您是否得到了解决方案的答案,但如果您还没有,并且您在 azure 中使用 redis 缓存进行非 ssl,也许您必须按照图中所示激活它。 enter image description here

关于azure - 将 AbortOnConnectFail 设置为 false 后,我们仍然会在 Azure REDIS 上收到 ConnectTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com