We use a redis server for caching some basic requests in our web apps. Recently we were seeing redis timeouts during testing… there was no server load, there were about 7 requests being processed a minute, and our redis server was reporting roughly 1% capacity for usage…. strange.
We were using the package Microsoft.Extensions.Caching.Redis Version 2.0.0 and had no problems with it before, but now under basic load, we were getting timeout errors.
A bit of investigation shows that the package hadn’t been updated in 2 years, and actually the updated version is Microsoft.Extensions.Caching.StackExchangeRedis Version 3.1.1 which was updated 11 hours ago at the time of writing this post. There were no links on the original nuget page to indicate that it had moved, you just had to figure it out.

Great! Maybe I’ve just been using some outdated libraries, and this will work better with our Azure Redis server, which was deployed at version 3.x.x but is now automatically updated to 4.x.x behind the scenes.
In theory I should be able to use my same config while only slightly tweaking my DI setup.
services.AddDistributedRedisCache(option => { option.Configuration = String.Format( Configuration.GetConnectionString("RedisCache"), Configuration.GetValue("RedisPassword")); option.InstanceName = Configuration.GetValue("RedisCacheInstance"); });
becomes:
services.AddStackExchangeRedisCache(option => { option.Configuration = String.Format( Configuration.GetConnectionString("RedisCache"), Configuration.GetValue("RedisPassword")); option.InstanceName = Configuration.GetValue("RedisCacheInstance"); });
internal static ConfigurationOptions PrepareConfig(object configuration) { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); ConfigurationOptions config; if (configuration is string s) { config = ConfigurationOptions.Parse(s); } else if (configuration is ConfigurationOptions configurationOptions) { config = (configurationOptions).Clone(); } else { throw new ArgumentException("Invalid configuration object", nameof(configuration)); } if (config.EndPoints.Count == 0) throw new ArgumentException("No endpoints specified", nameof(configuration)); config.SetDefaultPorts(); return config; }
services.AddStackExchangeRedisCache(option => { option.InstanceName = Configuration.GetValue<string>("RedisCacheInstance"); option.ConfigurationOptions = newConfigurationOptions() { EndPoints = { Configuration.GetValue<string>("RedisServer"), Configuration.GetValue<string>("RedisPort") }, Password = Configuration.GetValue<string>("RedisPassword"), ConnectRetry = 5, ReconnectRetryPolicy = newLinearRetry(1500), Ssl = true, AbortOnConnectFail = false, ConnectTimeout = 5000, SyncTimeout = 5000, DefaultDatabase = 0 }; });
Thank you so much for this, I’ve been through the same debugging as you have and found your brilliant post! Strange how sometimes those breaking changes are not made more public. Nuget really need some way to notify of deprecated packages (and newer alternatives).
LikeLiked by 1 person
Thank you so much
LikeLiked by 1 person
Thank you!!!
LikeLiked by 1 person