Redis Connection String Format
Build a Redis connection string with the redis:// or rediss:// URI format. Covers database selection, authentication, and TLS connections.
Detailed Explanation
Redis URI Format
Redis connection strings use the redis:// scheme (or rediss:// for TLS-encrypted connections):
redis://[user:password@]host[:port][/database]
rediss://[user:password@]host[:port][/database]
Default Values
| Parameter | Default |
|---|---|
| Host | localhost |
| Port | 6379 |
| Database | 0 |
| Username | (none) |
| Password | (none) |
Database Numbers
Unlike SQL databases that use names, Redis uses numbered databases from 0 to 15 (default configuration). The database number is specified as the path component:
redis://localhost:6379/0 # Default database
redis://localhost:6379/1 # Database 1
redis://localhost:6379/5 # Database 5
Authentication
Redis 5 and earlier only uses password authentication (no username):
redis://:mysecretpassword@localhost:6379/0
Note the colon before the password — the username is empty.
Redis 6+ (ACL) supports username + password via the ACL system:
redis://myuser:mypassword@localhost:6379/0
TLS / SSL Connections
For encrypted connections (common with Redis Cloud, ElastiCache, Upstash), use the rediss:// scheme (note the double 's'):
rediss://default:token@redis.example.com:6380/0
Sentinel and Cluster
Redis Sentinel and Cluster deployments use additional parameters that vary by client library. For example, with ioredis in Node.js:
// Sentinel
{
sentinels: [{ host: "sentinel1", port: 26379 }],
name: "mymaster",
password: "secret"
}
These configurations typically use object-based config rather than URI strings, as the URI format does not standardize Sentinel/Cluster parameters.
Use Case
Connecting a web application to Redis for session storage, caching, or pub/sub messaging — whether a local Redis instance or a managed service like Upstash or ElastiCache.