StackExchange.Redis
StackExchange.Redis copied to clipboard
`ConnectTimeout` exception was throw when use `new ConfigurationOptions`
But if I use ConfigurationOptions.Parse, everything works fine.
StackExchange.Redis.RedisConnectionException: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=EVAL, timeout: 5000, inst: 0, qu: 0, qs: 0, aw: False, bw: CheckingForTimeout, rs: NotStarted, ws: Idle, in: 0, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 1, serverEndpoint: localhost:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: Auth.Web, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=2,Max=32767), POOL: (Threads=3,QueuedItems=0,CompletedItems=54,Timers=2), v: 2.7.27.49176 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
public static IServiceCollection AddCaching(this IServiceCollection services, IConfiguration configuration)
{
services.AddStackExchangeRedisCache(options =>
{
var config = configuration.GetRedisConfiguration();
var a = new ConfigurationOptions
{
ClientName = config.ClientName,
DefaultDatabase = config.DefaultDatabase,
EndPoints = new EndPointCollection([.. config.EndPoints.Cast<EndPoint>()])
};
var b = ConfigurationOptions.Parse(a.ToString());
// Timeout when use a;
options.ConfigurationOptions = a;
// Worked when use b;
// options.ConfigurationOptions = b;
});
return services;
}
To answer this, we'd need to know what connection string is being parsed. They fundamentally take the same path under the covers so we are likely to see some difference in the parsed connection string. Based on your symptoms, I would assume that the endpoints are not being passed correctly to option a here and we time ever connecting. If you pass a string logger to the .Connect()/.ConnectAsync() methods, you can see a full connect log for what's going wrong which may make things more apparent.