@@ -67,12 +67,18 @@ replaced by ``rediss`` (the second ``s`` means "secure").
67
67
68
68
.. note ::
69
69
70
- A `Data Source Name (DSN) `_ for this adapter must use the following format .
70
+ A `Data Source Name (DSN) `_ for this adapter must use either one of the following formats .
71
71
72
72
.. code-block :: text
73
73
74
74
redis[s]://[pass@][ip|host|socket[:port]][/db-index]
75
75
76
+ .. code-block :: text
77
+
78
+ redis[s]:[[user]:pass@]?[ip|host|socket[:port]][¶ms]
79
+
80
+ Values for placeholders ``[user] ``, ``[:port] ``, ``[/db-index] `` and ``[¶ms] `` are optional.
81
+
76
82
Below are common examples of valid DSNs showing a combination of available values::
77
83
78
84
use Symfony\Component\Cache\Adapter\RedisAdapter;
@@ -89,8 +95,13 @@ Below are common examples of valid DSNs showing a combination of available value
89
95
// socket "/var/run/redis.sock" and auth "bad-pass"
90
96
RedisAdapter::createConnection('redis://bad-pass@/var/run/redis.sock');
91
97
92
- // a single DSN can define multiple servers using the following syntax:
93
- // host[hostname-or-IP:port] (where port is optional). Sockets must include a trailing ':'
98
+ // host "redis1" (docker container) with alternate DSN syntax and selecting database index "3"
99
+ RedisAdapter::createConnection('redis:?host[redis1:6379]&dbindex=3');
100
+
101
+ // providing credentials with alternate DSN syntax
102
+ RedisAdapter::createConnection('redis:default:verysecurepassword@?host[redis1:6379]&dbindex=3');
103
+
104
+ // a single DSN can also define multiple servers
94
105
RedisAdapter::createConnection(
95
106
'redis:?host[localhost]&host[localhost:6379]&host[/var/run/redis.sock:]&auth=my-password&redis_cluster=1'
96
107
);
@@ -103,6 +114,16 @@ parameter to set the name of your service group::
103
114
'redis:?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster'
104
115
);
105
116
117
+ // providing credentials
118
+ RedisAdapter::createConnection(
119
+ 'redis:default:verysecurepassword@?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster'
120
+ );
121
+
122
+ // providing credentials and selecting database index "3"
123
+ RedisAdapter::createConnection(
124
+ 'redis:default:verysecurepassword@?host[redis1:26379]&host[redis2:26379]&host[redis3:26379]&redis_sentinel=mymaster&dbindex=3'
125
+ );
126
+
106
127
.. note ::
107
128
108
129
See the :class: `Symfony\\ Component\\ Cache\\ Traits\\ RedisTrait ` for more options
@@ -124,29 +145,31 @@ array of ``key => value`` pairs representing option names and their respective v
124
145
125
146
// associative array of configuration options
126
147
[
127
- 'lazy ' => false ,
148
+ 'class ' => null ,
128
149
'persistent' => 0,
129
150
'persistent_id' => null,
130
- 'tcp_keepalive' => 0,
131
151
'timeout' => 30,
132
152
'read_timeout' => 0,
133
153
'retry_interval' => 0,
154
+ 'tcp_keepalive' => 0,
155
+ 'lazy' => null,
156
+ 'redis_cluster' => false,
157
+ 'redis_sentinel' => null,
158
+ 'dbindex' => 0,
159
+ 'failover' => 'none',
160
+ 'ssl' => null,
134
161
]
135
162
136
163
);
137
164
138
165
Available Options
139
166
~~~~~~~~~~~~~~~~~
140
167
141
- ``class `` (type: ``string ``)
168
+ ``class `` (type: ``string ``, default: `` null `` )
142
169
Specifies the connection library to return, either ``\Redis `` or ``\Predis\Client ``.
143
170
If none is specified, it will return ``\Redis `` if the ``redis `` extension is
144
- available, and ``\Predis\Client `` otherwise.
145
-
146
- ``lazy `` (type: ``bool ``, default: ``false ``)
147
- Enables or disables lazy connections to the backend. It's ``false `` by
148
- default when using this as a stand-alone component and ``true `` by default
149
- when using it inside a Symfony application.
171
+ available, and ``\Predis\Client `` otherwise. Explicitly set this to ``\Predis\Client `` for Sentinel if you are
172
+ running into issues when retrieving master information.
150
173
151
174
``persistent `` (type: ``int ``, default: ``0 ``)
152
175
Enables or disables use of persistent connections. A value of ``0 `` disables persistent
@@ -155,6 +178,10 @@ Available Options
155
178
``persistent_id `` (type: ``string|null ``, default: ``null ``)
156
179
Specifies the persistent id string to use for a persistent connection.
157
180
181
+ ``timeout `` (type: ``int ``, default: ``30 ``)
182
+ Specifies the time (in seconds) used to connect to a Redis server before the
183
+ connection attempt times out.
184
+
158
185
``read_timeout `` (type: ``int ``, default: ``0 ``)
159
186
Specifies the time (in seconds) used when performing read operations on the underlying
160
187
network resource before the operation times out.
@@ -167,9 +194,28 @@ Available Options
167
194
Specifies the `TCP-keepalive `_ timeout (in seconds) of the connection. This
168
195
requires phpredis v4 or higher and a TCP-keepalive enabled server.
169
196
170
- ``timeout `` (type: ``int ``, default: ``30 ``)
171
- Specifies the time (in seconds) used to connect to a Redis server before the
172
- connection attempt times out.
197
+ ``lazy `` (type: ``bool ``, default: ``null ``)
198
+ Enables or disables lazy connections to the backend. It's ``false `` by
199
+ default when using this as a stand-alone component and ``true `` by default
200
+ when using it inside a Symfony application.
201
+
202
+ ``redis_cluster `` (type: ``bool ``, default: ``false ``)
203
+ Enables or disables redis cluster. The actual value passed is irrelevant as long as it passes loose comparison
204
+ checks: `redis_cluster=1 ` will suffice.
205
+
206
+ ``redis_sentinel `` (type: ``string ``, default: ``null ``)
207
+ Specifies the master name connected to the sentinels.
208
+
209
+ ``dbindex `` (type: ``int ``, default: ``0 ``)
210
+ Specifies the database index to select.
211
+
212
+ ``failover `` (type: ``string ``, default: ``none ``)
213
+ Specifies failover for cluster implementations. For ``\RedisCluster `` valid options are ``none `` (default),
214
+ ``error ``, ``distribute `` or ``slaves ``. For ``\Predis\ClientInterface `` valid options are ``slaves ``
215
+ or ``distribute ``.
216
+
217
+ ``ssl `` (type: ``bool ``, default: ``null ``)
218
+ SSL context options. See `php.net/context.ssl `_ for more information.
173
219
174
220
.. note ::
175
221
@@ -217,3 +263,4 @@ Read more about this topic in the official `Redis LRU Cache Documentation`_.
217
263
.. _`TCP-keepalive` : https://redis.io/topics/clients#tcp-keepalive
218
264
.. _`Redis Sentinel` : https://redis.io/topics/sentinel
219
265
.. _`Redis LRU Cache Documentation` : https://redis.io/topics/lru-cache
266
+ .. _`php.net/context.ssl` : https://php.net/context.ssl
0 commit comments