StackExchange.Redis.Extensions
StackExchange.Redis.Extensions copied to clipboard
Redis connection error restored
In a basic console app when DI resolves in constructor a error log raised: "Redis connection error restored." It comes from ConnectionRestored in RedisCacheConnectionPoolManager.
DI config:
public static ServiceCollection RegisterCommonServices(this ServiceCollection services, RedisConfiguration redisConfiguration)
{
services.AddSingleton<ISerializer, NewtonsoftSerializer>();
services.AddSingleton(redisConfiguration);
services.AddSingleton<IRedisCacheClient, RedisCacheClient>();
services.AddSingleton<IRedisCacheConnectionPoolManager, RedisCacheConnectionPoolManager>();
services.AddSingleton((provider) =>
{
return provider.GetRequiredService<IRedisCacheClient>().GetDbFromConfiguration();
});
return services;
}
Config:
"Redis": {
"Hosts": [
{
"Host": "127.0.0.1",
"Port": "6379"
}
],
"Database": 0,
"ConnectTimeout": 60,
"ConnectRetry": 2,
"IdleTimeOutSecs": 120,
"Ssl": false,
"RequiresAuth": false,
"NamespacePrefix": "",
"PoolSize": 10,
"MaxValueLength": 102400,
"ConfigurationOptions": {
"KeepAlive": 10,
"ConnectTimeout": 30000,
"ResponseTimeout": 60000,
"AbortOnConnectFail": true,
"AsyncTimeout": 15000,
"SyncTimeout": 15000
}

I've tried multiple combinations without luck. Despite this, if I try to read or write to redis it works fine... but this error is a bit confusing. I don't know if I can ignore it...
up i had same error
Hi, there is a specific package for that
https://github.com/imperugo/StackExchange.Redis.Extensions/tree/master/src/aspnet/StackExchange.Redis.Extensions.AspNetCore
Here https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/samples/StackExchange.Redis.Samples.Web.Mvc/Startup.cs#L42 and example on "how to use it"
i still got the same error
How do you use it? Because I use it in production without problem. Also the code in this repo (see the example project) works fine. Please download it and try it.
Thanks
//register redis services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(new RedisConfiguration { ConnectionString = Configuration.GetConnectionString("AriPlusRedis"), PoolSize = 100, ServerEnumerationStrategy = new ServerEnumerationStrategy { Mode = ServerEnumerationStrategy.ModeOptions.All, TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any, UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw } });
in appsettings "AriPlusRedis": "redis-master,redis-replica,password=xxx,abortConnect=false,connectTimeout=15000,allowAdmin=true"
I can't see the serializer in your code, but I can see it here
https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/samples/StackExchange.Redis.Samples.Web.Mvc/Startup.cs#L42
That's the problem!
i updated my code but exception still throws :(
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(new RedisConfiguration { ConnectionString = Configuration.GetConnectionString("AriPlusRedis"), PoolSize = 100, ServerEnumerationStrategy = new ServerEnumerationStrategy { Mode = ServerEnumerationStrategy.ModeOptions.All, TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any, UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw } });
debian@ns3100181:~/ariplus-backend$ docker-compose -f docker-compose.yml logs web Attaching to ariplus-backend_web_2, ariplus-backend_web_1, ariplus-backend_web_4, ariplus-backend_web_3 web_1 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0] web_1 | Redis connection error restored. web_4 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0] web_4 | Redis connection error restored. web_4 | fail: StackExchange.Redis.Extensions.Core.Implementations.RedisCacheConnectionPoolManager[0] web_4 | Redis connection error restored.
I have removed PoolSize parameter but problem still continue
I have using totally same conf with sample but problem still continue
//register redis
var conf = new RedisConfiguration
{
AbortOnConnectFail = true,
Password = Configuration.GetValue
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(conf);
I'm getting the same error in my production logs. Digging deeper into sources for both StackExchange.Redis.Extensions and StackExchange.Redis , the error is logged when Redis connection is recovered from previous failure.
Strange enough, I don't see any mention of previous errors in my logs, and no other signs of crashing. My question here is: why is this event logged here as error? Why not warning, since it is a recovery event, not actual failure?
private void ConnectionRestored(object sender, ConnectionFailedEventArgs e)
{
logger.LogError("Redis connection error restored.");
}
Same issue for me. It does not appear if its its executed the first time, but after shut down and re-connection it begins to display this error
I have the same logs. It happens when I deploy the application only. I agree with @kirillito. I believe this should be logged as a warning.
I had the same issue in my setup. In my ASP.NET Core service I am using DataProtection and of course I would like to use Redis to store the Keys. At first I used the following code:
services
.AddDataProtection()
.SetDefaultKeyLifetime(TimeSpan.FromDays(keyLifeTime))
.PersistKeysToStackExchangeRedis(() =>
{
var sp = services.BuildServiceProvider();
var redisCacheConnectionPoolManager = sp.GetService<IRedisCacheConnectionPoolManager>();
return redisCacheConnectionPoolManager.GetConnection().GetDatabase();
}
, key)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
I have recognized that the "Redis connection error restored" error was printed when I was trying to get the IDatabase instance directly via the RedisCacheConnectionPoolManager.
Then I have changed the section like this:
services
.AddDataProtection()
.SetDefaultKeyLifetime(TimeSpan.FromDays(keyLifeTime))
.PersistKeysToStackExchangeRedis(() =>
{
var sp = services.BuildServiceProvider();
var redisClient = sp.GetService<IRedisCacheClient>();
return redisClient.GetDbFromConfiguration().Database;
}
, key)
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
});
Now I am getting a RedisClient from the managed Redis connection pool to retrieve the IDatabase instance and the error was gone.
Also have this bug, in V7 version.