@@ -107,11 +107,11 @@ $factory = new Factory($loop, $connector);
107
107
#### createClient()
108
108
109
109
The ` createClient($redisUri = null) ` method can be used to create a new [ ` Client ` ] ( #client ) .
110
- It helps with establishing a plain TCP/IP connection to Redis
110
+ It helps with establishing a plain TCP/IP or secure TLS connection to Redis
111
111
and optionally authenticating (AUTH) and selecting the right database (SELECT).
112
112
113
113
``` php
114
- $factory->createClient('localhost:6379')->then(
114
+ $factory->createClient('redis:// localhost:6379')->then(
115
115
function (Client $client) {
116
116
// client connected (and authenticated)
117
117
},
@@ -121,28 +121,56 @@ $factory->createClient('localhost:6379')->then(
121
121
);
122
122
```
123
123
124
- You can omit the complete URI if you want to connect to the default address ` localhost:6379 ` :
124
+ The ` $redisUri ` can be given in the
125
+ [ standard] ( https://www.iana.org/assignments/uri-schemes/prov/redis ) form
126
+ ` [redis[s]://][:auth@]host[:port][/db] ` .
127
+ You can omit the URI scheme and port if you're connecting to the default port 6379:
125
128
126
129
``` php
127
- $factory->createClient();
130
+ // both are equivalent due to defaults being applied
131
+ $factory->createClient('localhost');
132
+ $factory->createClient('redis://localhost:6379');
128
133
```
129
134
130
- You can omit the port if you're connecting to the default port 6379:
135
+ Redis supports password-based authentication (` AUTH ` command). Note that Redis'
136
+ authentication mechanism does not employ a username, so you can pass the
137
+ password ` h@llo ` URL-encoded (percent-encoded) as part of the URI like this:
131
138
132
139
``` php
133
- $factory->createClient('localhost');
140
+ // all forms are equivalent
141
+ $factory->createClient('redis://:h%40llo@localhost');
142
+ $factory->createClient('redis://ignored:h%40llo@localhost');
143
+ $factory->createClient('redis://localhost?password=h%40llo');
134
144
```
135
145
136
- You can optionally include a password that will be used to authenticate (AUTH command) the client:
146
+ > Legacy notice: The ` redis:// ` scheme is defined and preferred as of ` v1.2.0 ` .
147
+ For BC reasons, the ` Factory ` defaults to the ` tcp:// ` scheme in which case
148
+ the authentication details would include the otherwise unused username.
149
+ This legacy API will be removed in a future ` v2.0.0 ` version, so it's highly
150
+ recommended to upgrade to the above API.
151
+
152
+ You can optionally include a path that will be used to select (SELECT command) the right database:
137
153
138
154
``` php
139
- $factory->createClient('auth@localhost');
155
+ // both forms are equivalent
156
+ $factory->createClient('redis://localhost/2');
157
+ $factory->createClient('redis://localhost?db=2');
140
158
```
141
159
142
- You can optionally include a path that will be used to select (SELECT command) the right database:
160
+ You can use the [ standard] ( https://www.iana.org/assignments/uri-schemes/prov/rediss )
161
+ ` rediss:// ` URI scheme if you're using a secure TLS proxy in front of Redis:
162
+
163
+ ``` php
164
+ $factory->createClient('rediss://redis.example.com:6340');
165
+ ```
166
+
167
+ [ Deprecated] You can omit the complete URI if you want to connect to the default
168
+ address ` redis://localhost:6379 ` . This legacy API will be removed in a future
169
+ ` v2.0.0 ` version, so it's highly recommended to upgrade to the above API.
143
170
144
171
``` php
145
- $factory->createClient('localhost/2');
172
+ // deprecated
173
+ $factory->createClient();
146
174
```
147
175
148
176
### Client
0 commit comments