Redis Cache Connection Resiliency – Best Practices

Today in this article we shall see how to implement Redis Cache Connection Resiliency with examples in the .NET application.
Updated November 2026: a section on keeping the app running when Redis is down, a section on slow recovery and timeout tuning, and an FAQ.
We will use StackExchange.Redis NuGet package for getting supported connection manager class for performing connection or re-connections or timeout configuration.
Connection resiliency is a critical component of application communication that uses shared resources (particularly in the cloud) because these resources are more vulnerable to transient faults.
The StackExchange.Redis client uses a connection manager class that is configured through a set of options, including:
Configuring the ConnectionMultiplexer with resiliency options
Below is a sample example of how to configure the ConnectionMultiplexer with resiliency options. Below we have used an instance of the configuration options class, with required options defined and passing it to the Connect method.
Retry policies are configured before connecting to the cache.
Connection Resiliency for Redis- Retry with exponential backoff
The below example shows a retry strategy using exponential backoff.
var options = new ConfigurationOptions
{
EndPoints = { $"{Configuration.GetValue<string>("RedisCache:Host")}:
{Configuration.GetValue<int>("RedisCache:Port")}" },
ConnectRetry = 5,
ReconnectRetryPolicy = new ExponentialRetry(deltaBackOffms ,
maxdeltaBackOffms),
ConnectTimeout = 1000
};
var redisMultiplexer = ConnectionMultiplexer.Connect(options);
Above time in milliseconds can be defined as the below example,
var deltaBackOffms =
Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds);
var maxdeltaBackOffms =
Convert.ToInt32(TimeSpan.FromSeconds(20).TotalMilliseconds);
ConfigurationOptions discussed above are defined as below,
- ConnectRetry – The number of times to repeat connect attempts during the initial connection operation. The default value is 3.
- ReconnectRetryPolicy. The retry strategy to use. The default value is LinearRetry 5000 ms
- ConnectTimeout. The maximum waiting time is in milliseconds.
Connection Resiliency for Redis – Retry using string options
Alternatively, we can define configuration via string declaration as below
var configOptions = $"{host},connectRetry=3,connectTimeout=1000";
var redisMultiplexer = ConnectionMultiplexer.Connect(configOptions);
services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
Where ‘host‘ is defined as below,
var host = $"{Configuration.GetValue("RedisCache:Host")}:
{Configuration.GetValue("RedisCache:Port")}";
Above we are making use of the configuration to read the apsetting.json file,
For more details: Configuration in ASP.NET Core
Using ConnectionMultiplexer via Dependency Injection
if you are using ASP.NET Core or MVC application, then ConnectionMultiplexer via Dependency Injection can be injected by defining the service scope in the API pipeline as below,
services.AddSingleton(redisMultiplexer);
For more details: Redis-Dependency Injection of the ConnectionMultiplexer
How to keep an ASP.NET Core app running when Redis is down
Set abortConnect=false (AbortOnConnectFail = false) so the app starts even if Redis is unreachable and the multiplexer keeps retrying in the background. That only fixes reconnecting. You still have to handle the commands that fail while the cache is gone.
Why does the app crash at startup when Redis is unavailable?
AbortOnConnectFail defaults to true for non-Azure endpoints. If Redis is briefly unreachable during startup, the first connect throws “it was not possible to connect to the redis server(s)” and no multiplexer is created. Older guidance says Azure Redis endpoints already default to false, but set it explicitly so you don’t depend on that.
Note: Think of a shop that refuses to open because one delivery is late, versus one that opens and keeps phoning the supplier.
abortConnect=falseis the second shop. The analogy stops at commands: customers still can’t buy the late item until it arrives.
What does abortConnect=false not protect you from?
Individual commands can still throw RedisConnectionException or RedisTimeoutException during an outage. The multiplexer reconnects, but it doesn’t swallow errors for you, so your code has to catch them.
StackExchange.Redis can also occasionally fail to reconnect after a dropped connection. Creating a new multiplexer fixes it. Microsoft’s answer is a singleton multiplexer that can be forced to reconnect: call ForceReconnectAsync when you see RedisConnectionException or RedisSocketException.
If you use AddStackExchangeRedisCache from Microsoft.Extensions.Caching.StackExchangeRedis, don’t hand-write that pattern. Set the UseForceReconnect property to true and the package does it for you.
How do you fall back to the database when the cache fails?
Use cache-aside and treat Redis as optional. Wrap your IDistributedCache calls in a try/catch for the Redis exceptions, log them, and read from the source of truth instead. Responses get slower and your database takes more load, so size for that.
A dead cache can also make every request wait for a timeout. Add a short timeout and a circuit breaker with Polly or Microsoft.Extensions.Resilience. After a few failures the breaker skips Redis entirely for a while, then probes it again.
How do you know Redis is having trouble?
Subscribe to the multiplexer’s ConnectionFailed and ConnectionRestored events and write them to your logs. Outage start and end times then show up next to your slow-request alerts.
Expose Redis connectivity through a health check. Be careful what you attach it to. If your fallback works, a failing Redis shouldn’t fail the readiness probe, or every instance leaves the load balancer at once. Report it as degraded and alert on it instead.
Create the multiplexer once at startup and share it. A per-request multiplexer opens a new connection each time, which adds load exactly when Redis is struggling.
Redis Retry guidelines
Consider the following guidelines when using Azure Managed Redis or Azure Cache for Redis (Microsoft has announced a retirement timeline for Azure Cache for Redis and recommends migrating to Azure Managed Redis),
- Retry policies apply when establishing a connection to the cache, and with abortConnect set to false the multiplexer also keeps reconnecting in the background after a drop (when the application first starts.)
- It’s recommended to use falling back by accessing an original data source. This is preferred over a number of retry attempts.
Other useful references :
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.
Frequently asked questions
What does abortConnect=false do in StackExchange.Redis?
It sets AbortOnConnectFail to false. With the default of true for non-Azure endpoints, the initial connect throws “it was not possible to connect to the redis server(s)” if Redis is briefly unreachable, and no multiplexer is created. With false, the app starts and the client keeps retrying in the background. Commands issued while the connection is down can still fail, so handle the exceptions or fall back to your primary data store.
What is ForceReconnect and when should I use it?
ForceReconnect is a pattern that replaces the ConnectionMultiplexer with a new one when the old one won’t recover. StackExchange.Redis can occasionally fail to recover from a dropped connection until a new multiplexer is created. The pattern triggers when a RedisConnectionException or RedisSocketException occurs. If your app uses Microsoft.Extensions.Caching.StackExchangeRedis, set UseForceReconnect to true instead of hand-writing the pattern.
Should ConnectionMultiplexer be a singleton in ASP.NET Core?
Yes. It uses one multiplexed connection per server, and that connection is safe to share across threads. Create it once at startup and reuse it through dependency injection. Creating one per request exhausts connections and slows every call.
Why does my Redis connection take many minutes to recover on Linux?
The default TCP retry settings on some Linux versions can keep a connection failing for 13 minutes or more after a silent network drop. Microsoft documents lowering net.ipv4.tcp_retries2 on Linux-hosted clients to shorten this. Other client libraries are affected too, so this isn’t specific to StackExchange.Redis.
