@@ -107,11 +107,11 @@ $factory = new Factory($loop, $connector);
107107#### createClient()
108108
109109The ` 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
111111and optionally authenticating (AUTH) and selecting the right database (SELECT).
112112
113113``` php
114- $factory->createClient('localhost:6379')->then(
114+ $factory->createClient('redis:// localhost:6379')->then(
115115 function (Client $client) {
116116 // client connected (and authenticated)
117117 },
@@ -121,28 +121,56 @@ $factory->createClient('localhost:6379')->then(
121121);
122122```
123123
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:
125128
126129``` php
127- $factory->createClient();
130+ // both are equivalent due to defaults being applied
131+ $factory->createClient('localhost');
132+ $factory->createClient('redis://localhost:6379');
128133```
129134
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:
131138
132139``` 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');
134144```
135145
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:
137153
138154``` php
139- $factory->createClient('auth@localhost');
155+ // both forms are equivalent
156+ $factory->createClient('redis://localhost/2');
157+ $factory->createClient('redis://localhost?db=2');
140158```
141159
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.
143170
144171``` php
145- $factory->createClient('localhost/2');
172+ // deprecated
173+ $factory->createClient();
146174```
147175
148176### Client
0 commit comments