Redis connection string format
localhost:6379,password=secret,ssl=true,abortConnect=false
Examples
| Case | Connection string |
|---|---|
| Local Redis | localhost:6379 |
| Local Redis with a password | localhost:6379,password=secret,abortConnect=false |
| Azure Cache for Redis (TLS on 6380) | my-cache.redis.cache.windows.net:6380,password=secret,ssl=True,abortConnect=False |
| Redis 6+ ACL user, database 2 | redis.example.com:6379,user=app,password=secret,defaultDatabase=2,ssl=true |
| Sentinel | sentinel1:26379,sentinel2:26379,serviceName=mymaster,password=secret |
Every example on this page is checked with StackExchange.Redis itself. Replace the passwords with your own, and keep real ones out of source control.
The format
A StackExchange.Redis configuration string is a comma-separated list. Entries without = are endpoints (host:port); the rest are key=value options, with case-insensitive keys. There is no escaping, so a password cannot contain a comma: the text after the comma becomes another endpoint. Set ConfigurationOptions.Password in code for such passwords.
abortConnect=false
By default ConnectionMultiplexer.Connect throws if no server is reachable at startup. With abortConnect=false it returns anyway and keeps reconnecting in the background, which is what a web app wants: a Redis restart then does not take the app down. The Azure defaults already use false.
Surprises the checker shows
Unknown keys throw ("Keyword 'x' is not supported"). An endpoint with an invalid port, such as redis:abc, is dropped without an error, and a port above 65535 throws. Repeated endpoints are merged, ignoring case.
Where to keep it
Put it under ConnectionStrings in appsettings.json and read it with builder.Configuration.GetConnectionString("Default"). Keep passwords out of the file: user secrets in development, and an environment variable (ConnectionStrings__Default) or a secret store in production.
FAQ
How do I connect to Redis from C#?
Install StackExchange.Redis and call ConnectionMultiplexer.Connect(configuration) once, at startup. Share the multiplexer (register IConnectionMultiplexer as a singleton); do not create one per request.
Why does my Azure Cache for Redis connection fail?
Azure requires TLS: use port 6380 with ssl=True. Port 6379 (no TLS) is disabled by default.
What does abortConnect=false do?
Connect no longer throws when Redis is unreachable at startup; the multiplexer keeps retrying in the background.
Can I use a redis:// URL?
No. StackExchange.Redis 3.3 reads the comma-separated format and takes a whole redis:// URL as one host name, so parsing succeeds and connecting fails. Rewrite redis://:pass@host:6379 as host:6379,password=pass (rediss:// means ssl=true).
How do I use it for IDistributedCache?
Add Microsoft.Extensions.Caching.StackExchangeRedis and call AddStackExchangeRedisCache(o => o.Configuration = connectionString).
Other databases
- PostgreSQL connection string
- SQL Server connection string
- MySQL connection string
- SQLite connection string
- MongoDB connection string
- Connection string builder for every database