SncRedisBundle supports configuring Redis connections using a Data Source Name (DSN) string. The DSN follows the standard Redis URI format and can include credentials, host/socket information, database selection, and various query parameters.
Supported URI Schemes
redis:// for standard connections.rediss:// for TLS/SSL connections.
DSN Components
- Credentials:
username:password@ (both are URL-encoded). - Host/Socket: A hostname, IP address (including IPv6 in
[]), or a Unix socket path starting with /. - Port: Specified after a colon (e.g.,
:6379). - Database: Specified as a path suffix (e.g.,
/0 or /my_db). - Query Parameters: Appended via
? to configure bundle-specific options.
Supported Query Parameters
| Parameter | Description |
|---|
weight | Integer weight for connection pooling/selection |
alias | An alias for the connection |
role | The Redis role (e.g., master, slave) |
prefix | A key prefix to be applied to all keys |
tls_version | The TLS version to use |
Examples
Standard connection with password:
redis://:password@127.0.0.1:6379/0
TLS connection with username and password:
rediss://user:password@redis.example.com:6379/0?tls_version=tlsv1.2
Unix socket connection:
redis:///var/run/redis/redis.sock?prefix=my_app_
IPv6 connection:
redis://[2001:db8::1]:6379/0
redis://[user:password@]host[:port][/database][?param1=val1¶m2=val2]