@@ -55,18 +55,24 @@ helper method allows creating and configuring the Redis client class instance us
55
55
'redis://localhost'
56
56
);
57
57
58
- The DSN can specify either an IP/host (and an optional port) or a socket path, as
59
- well as a database index. To enable TLS for connections, the scheme ``redis `` must
60
- be replaced by ``rediss `` (the second ``s `` means "secure").
58
+ The DSN can specify either an IP/host (and an optional port) or a socket path, as well as a
59
+ password and a database index. To enable TLS for connections, the scheme ``redis `` must be
60
+ replaced by ``rediss `` (the second ``s `` means "secure").
61
61
62
62
.. note ::
63
63
64
- A `Data Source Name (DSN) `_ for this adapter must use the following format .
64
+ A `Data Source Name (DSN) `_ for this adapter must use either one of the following formats .
65
65
66
66
.. code-block :: text
67
67
68
68
redis[s]://[pass@][ip|host|socket[:port]][/db-index]
69
69
70
+ .. code-block :: text
71
+
72
+ redis[s]:[[user]:pass@]?[ip|host|socket[:port]][¶ms]
73
+
74
+ Values for placeholders ``[user] ``, ``[:port] ``, ``[/db-index] `` and ``[¶ms] `` are optional.
75
+
70
76
Below are common examples of valid DSNs showing a combination of available values::
71
77
72
78
use Symfony\Component\Cache\Adapter\RedisAdapter;
@@ -83,8 +89,11 @@ Below are common examples of valid DSNs showing a combination of available value
83
89
// socket "/var/run/redis.sock" and auth "bad-pass"
84
90
RedisAdapter::createConnection('redis://bad-pass@/var/run/redis.sock');
85
91
86
- // a single DSN can define multiple servers using the following syntax:
87
- // host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':'
92
+ // host "redis1" (docker container) with alternate DSN syntax and selecting database index "3"
93
+ RedisAdapter::createConnection('redis:?host[redis1:6379]&dbindex=3');
94
+
95
+ // providing credentials with alternate DSN syntax
96
+ RedisAdapter::createConnection('redis:default:verysecurepassword@?host[redis1:6379]&dbindex=3');
88
97
89
98
// a single DSN can also define multiple servers
90
99
RedisAdapter::createConnection(
@@ -99,6 +108,16 @@ parameter to set the name of your service group::
99
108
'redis:?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster'
100
109
);
101
110
111
+ // providing credentials
112
+ RedisAdapter::createConnection(
113
+ 'redis:default:verysecurepassword@?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster'
114
+ );
115
+
116
+ // providing credentials and selecting database index "3"
117
+ RedisAdapter::createConnection(
118
+ 'redis:default:verysecurepassword@?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster&dbindex=3'
119
+ );
120
+
102
121
.. note ::
103
122
104
123
See the :class: `Symfony\\ Component\\ Cache\\ Traits\\ RedisTrait ` for more options
0 commit comments