Your .NET app starts, calls Redis, and dies with It was not possible to connect to the redis server(s). The same string works on one machine and fails on another, and adding abortConnect=false only changes what you see next.
The StackExchange.Redis connection string is almost always the cause: a wrong host or port, a missing ssl=true or password=, a firewall in the way, or an app that creates a new connection on every request. The checks and the code below were run on .NET 10 with StackExchange.Redis 3.4.35 against a local Redis 8.12; the settings are documented in the StackExchange.Redis configuration reference.
The diagram shows how to read the message and where to go next.

- Which connection string setting fixes the error?
- Prerequisites
- Why StackExchange.Redis cannot connect
- Diagnostic checklist
- A working connection string
- Step 1: Connect with one shared multiplexer
- Step 2: Register it in ASP.NET Core
- Azure Cache for Redis specifics
- What each failure looks like
- Troubleshooting table
- Frequently asked questions
- Summary
Which connection string setting fixes the error?
- Wrong or unreachable endpoint: fix host and port, firewall, DNS or
ssl.abortConnect=falsewill not help. - Authentication failure: the message mentions
NOAUTHorWRONGPASS. Fixpassword=(anduser=for ACL users). - Redis simply starts later than your app: set
abortConnect=falseandconnectRetryso the client keeps retrying in the background. - New connection per request: create one
ConnectionMultiplexerand reuse it.
Prerequisites
- A .NET 10 SDK (the same code compiles on .NET 8 and 9, which were not run here).
- The
StackExchange.RedisNuGet package:dotnet add package StackExchange.Redis(3.4.35 was tested). - A Redis server you can reach, and its host, port, password and whether it requires TLS.
redis-clior any TCP test tool for the checklist below.
Why StackExchange.Redis cannot connect
abortConnect (AbortOnConnectFail in code) defaults to true, and false on Azure endpoints. With true, Connect() throws this exception when no server can be reached after connectRetry attempts (default 3) of connectTimeout (default 5000 ms) each. The usual reasons:
- Wrong host or port. Redis defaults to 6379. A typo, a container name that does not resolve from your network, or
localhostused inside a container. - Firewall or network security group. The port is blocked between client and server, or your client IP is not on the server allow list.
- TLS mismatch.
ssl=trueagainst a plain port, or a plain connection against a TLS-only port. Azure Cache for Redis uses 6380 for TLS and 6379 for non-TLS (disabled by default on new caches). - Password. Missing or wrong. This gives an authentication failure rather than a plain timeout.
- DNS. The name does not resolve, or resolves to a private address your client cannot reach (private endpoint).
- Timeouts. A high-latency link, busy server or starved client thread pool and a
connectTimeoutthat is too short. - Redis not up yet. The app starts before the Redis container or service.
- Connection churn. Creating and disposing a multiplexer per call exhausts sockets and makes timeouts more likely.
Diagnostic checklist
Work top to bottom. Each step rules out one layer.
- Print the exact connection string the app uses (without the password) and confirm host and port.
- From the same machine or container as the app, run
redis-cli -h HOST -p PORT ping. For TLS add--tls. If this fails, the problem is not your C# code. - If it fails, test the port alone (
nc -vz HOST PORT) and the name (nslookup HOST) to separate DNS, firewall and server problems. - If the server needs a password, run
redis-cli -a PASSWORD pingand compare with the app’spassword=. - Match TLS: TLS port needs
ssl=true, plain port needs nossl. - Read the full exception message. After the first sentence it names the endpoint and the inner cause, such as
NOAUTH. - Only then tune
connectTimeout,connectRetryandabortConnect.
A working connection string
A typical connection string for a TLS server with a password. Keep the password in user secrets, environment variables or a key vault, not in source control:
abortConnect=false:Connect()returns a disconnected multiplexer and retries in the background instead of throwing. It hides the symptom, so checkIsConnected.ssl=true: use TLS. Required on port 6380 of Azure Cache for Redis.connectRetryandconnectTimeout: attempts during the firstConnect(), and milliseconds per attempt.- Several servers are comma separated:
host1:6379,host2:6379.
More detail on TLS setup is in connecting to Redis with SSL/TLS in C# and connecting to a remote Redis server with auth.
Step 1: Connect with one shared multiplexer
This console program was compiled and run on .NET 10. It creates the multiplexer once through Lazy<T>, uses retry options, and reads and writes a key:
using StackExchange.Redis;
var options = ConfigurationOptions.Parse("127.0.0.1:6379");
options.AbortOnConnectFail = false; // keep retrying in the background
options.ConnectRetry = 5; // attempts during Connect()
options.ConnectTimeout = 5000; // ms per attempt
options.ReconnectRetryPolicy = new ExponentialRetry(5000);
var shared = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(options));
var db = shared.Value.GetDatabase();
await db.StringSetAsync("demo:key", "hello", TimeSpan.FromMinutes(1));
Console.WriteLine($"connected={shared.Value.IsConnected}, value={await db.StringGetAsync("demo:key")}");
To see the error itself, catch RedisConnectionException and print FailureType:
try
{
using var mux = ConnectionMultiplexer.Connect("127.0.0.1:6399,connectTimeout=2000,connectRetry=1");
}
catch (RedisConnectionException ex)
{
Console.WriteLine($"{ex.FailureType}: {ex.Message}");
}
Step 2: Register it in ASP.NET Core
In ASP.NET Core register one IConnectionMultiplexer as a singleton and inject it where needed. Compiled and run with Microsoft.Extensions.DependencyInjection; resolving it twice returned the same instance:
services.AddSingleton<IConnectionMultiplexer>(_ =>
{
var options = ConfigurationOptions.Parse(configuration.GetConnectionString("Redis")!);
options.AbortOnConnectFail = false;
options.ConnectRetry = 5;
options.ReconnectRetryPolicy = new ExponentialRetry(5000);
return ConnectionMultiplexer.Connect(options);
});
Do not create a multiplexer inside a controller or per request, and do not wrap it in using in request code. For a longer walkthrough see Redis dependency injection with ConnectionMultiplexer and Redis connection resiliency best practices. Microsoft also recommends a singleton multiplexer and abortConnect=false in its connection best practices.
Azure Cache for Redis specifics
- Use the host name from the portal (
NAME.redis.cache.windows.net), the TLS port 6380,ssl=trueand an access key as the password. Non-TLS access on 6379 is off by default on new caches. See the cache configuration docs. - If the cache has a firewall, add your client IP. With a private endpoint, public network access may be disabled by default, so the client must be inside the network or have access enabled.
- If you use a third-party firewall or proxy, allow
*.redis.cache.windows.netand ports 6379 and 6380. Clustered caches may need more ports. - Microsoft’s connectivity troubleshooting guide covers these checks in detail.
- Azure endpoints already default to
abortConnect=false, so on Azure a failed first connection usually shows up later as timeouts. Check the endpoint and port shown in the portal for your tier.
What each failure looks like
Run against a local Redis 8.12 with one server on a plain port, one with requirepass, and one closed port. Messages shortened:
| Test | Connection string setting | Result |
|---|---|---|
| 1 | Closed port, default abortConnect | UnableToConnect: It was not possible to connect to the redis server(s). Error connecting right now… |
| 2 | Same port, abortConnect=false | No exception, IsConnected=False |
| 3 | Server with password, none supplied | AuthenticationFailure: … NOAUTH Returned - connection has not yet authenticated |
| 4 | Same server, password= correct | IsConnected=True |
| 5 | ssl=true against a non-TLS port | UnableToConnect (same text as test 1) |
| 6 | Shared multiplexer with retry options | connected, value read back, ping succeeded |
Test 5 shows why the first sentence of the message is not enough: a TLS mismatch looks the same as a closed port, so check TLS and the port together.
Troubleshooting table
| Symptom | Likely cause | Fix |
|---|---|---|
UnableToConnect immediately | Nothing listening, wrong host or port | Verify with redis-cli ping from the app’s machine |
UnableToConnect after about 5 seconds per attempt | Firewall or NSG drops packets, or private endpoint | Open the port, add client IP, check network path |
AuthenticationFailure, NOAUTH or WRONGPASS | Missing or wrong password or user | Set password= (and user=); on Azure use the access key |
| Fails only on the TLS port | ssl not set | Add ssl=true |
| Fails only on the plain port | ssl=true against non-TLS server | Remove ssl or use the TLS port |
| Works locally, fails in a container | localhost points to the container itself | Use the Redis service name or host address |
| App starts, then Redis calls fail | abortConnect=false hid a bad endpoint | Log IsConnected; fix the endpoint, not the flag |
| Timeouts under load | Multiplexer created per request, or short connectTimeout | One shared multiplexer, keep default timeouts unless measured |
Frequently asked questions
What does abortConnect=false do in StackExchange.Redis?
It makes Connect() return a multiplexer even if no server is reachable, and the client keeps retrying in the background. The app starts, but commands fail until a connection exists, so it does not fix a wrong host, port or password.
Why do I get ‘It was not possible to connect to the redis server(s)’ with the right host?
Usual remaining causes are a TLS mismatch (ssl=true against a plain port or the reverse), a firewall or network rule, a wrong password, or DNS resolving to an address the client cannot reach. Run redis-cli ping from the same machine and read the full exception message.
Should I create a ConnectionMultiplexer for every request?
No. Create one and share it for the life of the app, for example as an ASP.NET Core singleton. It multiplexes many commands over a few connections, and creating many wastes sockets and can cause timeouts.
Summary
Read the exception text, run redis-cli ping from the app’s machine, and match host, port, ssl and password before changing anything else. Then add abortConnect=false and retry settings, and share one multiplexer. Tested here: .NET 10, StackExchange.Redis 3.4.35, local Redis 8.12 on plain ports, including a password-protected server, a closed port, a TLS mismatch and a DI singleton. Not tested: a real TLS server, Azure Cache for Redis, clusters or Sentinel, .NET 8 and 9, and firewall or DNS failures.
Found this useful?
Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.
