@@ -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,20 +95,35 @@ 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
);
97
108
98
109
`Redis Sentinel `_, which provides high availability for Redis, is also supported
99
- when using the Predis library. Use the ``redis_sentinel `` parameter to set the
100
- name of your service group::
110
+ when using the PHP Redis Extension v5.2+ or the Predis library. Use the ``redis_sentinel ``
111
+ parameter to set the name of your service group::
101
112
102
113
RedisAdapter::createConnection(
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
.. versionadded :: 4.2
107
128
108
129
The option to define multiple servers in a single DSN was introduced in Symfony 4.2.
@@ -132,29 +153,31 @@ array of ``key => value`` pairs representing option names and their respective v
132
153
133
154
// associative array of configuration options
134
155
[
135
- 'lazy ' => false ,
156
+ 'class ' => null ,
136
157
'persistent' => 0,
137
158
'persistent_id' => null,
138
- 'tcp_keepalive' => 0,
139
159
'timeout' => 30,
140
160
'read_timeout' => 0,
141
161
'retry_interval' => 0,
162
+ 'tcp_keepalive' => 0,
163
+ 'lazy' => null,
164
+ 'redis_cluster' => false,
165
+ 'redis_sentinel' => null,
166
+ 'dbindex' => 0,
167
+ 'failover' => 'none',
168
+ 'ssl' => null,
142
169
]
143
170
144
171
);
145
172
146
173
Available Options
147
174
~~~~~~~~~~~~~~~~~
148
175
149
- ``class `` (type: ``string ``)
176
+ ``class `` (type: ``string ``, default: `` null `` )
150
177
Specifies the connection library to return, either ``\Redis `` or ``\Predis\Client ``.
151
178
If none is specified, it will return ``\Redis `` if the ``redis `` extension is
152
- available, and ``\Predis\Client `` otherwise.
153
-
154
- ``lazy `` (type: ``bool ``, default: ``false ``)
155
- Enables or disables lazy connections to the backend. It's ``false `` by
156
- default when using this as a stand-alone component and ``true `` by default
157
- when using it inside a Symfony application.
179
+ available, and ``\Predis\Client `` otherwise. Explicitly set this to ``\Predis\Client `` for Sentinel if you are
180
+ running into issues when retrieving master information.
158
181
159
182
``persistent `` (type: ``int ``, default: ``0 ``)
160
183
Enables or disables use of persistent connections. A value of ``0 `` disables persistent
@@ -163,6 +186,10 @@ Available Options
163
186
``persistent_id `` (type: ``string|null ``, default: ``null ``)
164
187
Specifies the persistent id string to use for a persistent connection.
165
188
189
+ ``timeout `` (type: ``int ``, default: ``30 ``)
190
+ Specifies the time (in seconds) used to connect to a Redis server before the
191
+ connection attempt times out.
192
+
166
193
``read_timeout `` (type: ``int ``, default: ``0 ``)
167
194
Specifies the time (in seconds) used when performing read operations on the underlying
168
195
network resource before the operation times out.
@@ -175,9 +202,28 @@ Available Options
175
202
Specifies the `TCP-keepalive `_ timeout (in seconds) of the connection. This
176
203
requires phpredis v4 or higher and a TCP-keepalive enabled server.
177
204
178
- ``timeout `` (type: ``int ``, default: ``30 ``)
179
- Specifies the time (in seconds) used to connect to a Redis server before the
180
- connection attempt times out.
205
+ ``lazy `` (type: ``bool ``, default: ``null ``)
206
+ Enables or disables lazy connections to the backend. It's ``false `` by
207
+ default when using this as a stand-alone component and ``true `` by default
208
+ when using it inside a Symfony application.
209
+
210
+ ``redis_cluster `` (type: ``bool ``, default: ``false ``)
211
+ Enables or disables redis cluster. The actual value passed is irrelevant as long as it passes loose comparison
212
+ checks: `redis_cluster=1 ` will suffice.
213
+
214
+ ``redis_sentinel `` (type: ``string ``, default: ``null ``)
215
+ Specifies the master name connected to the sentinels.
216
+
217
+ ``dbindex `` (type: ``int ``, default: ``0 ``)
218
+ Specifies the database index to select.
219
+
220
+ ``failover `` (type: ``string ``, default: ``none ``)
221
+ Specifies failover for cluster implementations. For ``\RedisCluster `` valid options are ``none `` (default),
222
+ ``error ``, ``distribute `` or ``slaves ``. For ``\Predis\ClientInterface `` valid options are ``slaves ``
223
+ or ``distribute ``.
224
+
225
+ ``ssl `` (type: ``bool ``, default: ``null ``)
226
+ SSL context options. See `php.net/context.ssl `_ for more information.
181
227
182
228
.. note ::
183
229
@@ -225,3 +271,4 @@ Read more about this topic in the offical `Redis LRU Cache Documentation`_.
225
271
.. _`TCP-keepalive` : https://redis.io/topics/clients#tcp-keepalive
226
272
.. _`Redis Sentinel` : https://redis.io/topics/sentinel
227
273
.. _`Redis LRU Cache Documentation` : https://redis.io/topics/lru-cache
274
+ .. _`php.net/context.ssl` : https://php.net/context.ssl
0 commit comments