- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们在 .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 - 将 AbortOnConnectFail 设置为 false 后,我们仍然会在 Azure REDIS 上收到 ConnectTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685712/
我正在尝试制作一个从 azure redis 缓存读取和写入的简单示例,但收到此错误 An exception of type 'StackExchange.Redis.RedisConnection
我们在 .NET Core 2.0 Azure 应用服务中偶然收到以下错误日志: StackExchange.Redis.RedisConnectionException: No connection
我们在 .NET Core 2.0 Azure 应用服务中偶然收到以下错误日志: StackExchange.Redis.RedisConnectionException: No connection
我是一名优秀的程序员,十分优秀!