@@ -45,16 +45,17 @@ local Redis server and send some requests:
45
45
$loop = React\EventLoop\Factory::create();
46
46
$factory = new Factory($loop);
47
47
48
- $factory->createClient()->then(function (Client $client) use ($loop) {
49
- $client->SET ('greeting', 'Hello world');
50
- $client->APPEND ('greeting', '!');
48
+ $factory->createClient('localhost:6379' )->then(function (Client $client) use ($loop) {
49
+ $client->set ('greeting', 'Hello world');
50
+ $client->append ('greeting', '!');
51
51
52
- $client->GET('greeting')->then(function ($greeting) {
52
+ $client->get('greeting')->then(function ($greeting) {
53
+ // Hello world!
53
54
echo $greeting . PHP_EOL;
54
55
});
55
56
56
- $client->INCR ('invocation')->then(function ($n) {
57
- echo 'count: ' . $n . PHP_EOL;
57
+ $client->incr ('invocation')->then(function ($n) {
58
+ echo 'This is invocation # ' . $n . PHP_EOL;
58
59
});
59
60
60
61
// end connection once all pending requests have been resolved
@@ -87,24 +88,44 @@ $factory = new Factory($loop, $connector);
87
88
88
89
#### createClient()
89
90
90
- The ` createClient($redisUri) ` method can be used to create a new [ ` Client ` ] ( #client ) .
91
+ The ` createClient($redisUri = null ) ` method can be used to create a new [ ` Client ` ] ( #client ) .
91
92
It helps with establishing a plain TCP/IP connection to Redis
92
93
and optionally authenticating (AUTH) and selecting the right database (SELECT).
93
94
94
95
``` php
95
- $factory->createClient('localhost')->then(
96
+ $factory->createClient('localhost:6379 ')->then(
96
97
function (Client $client) {
97
- // client connected and authenticated
98
+ // client connected ( and authenticated)
98
99
},
99
100
function (Exception $e) {
100
- // an error occured while trying to connect or authorize client
101
+ // an error occured while trying to connect ( or authenticate) client
101
102
}
102
103
);
103
104
```
104
105
105
- > Note: The given $redisUri * can* include a scheme, password, host, port and database definition.
106
- >
107
- > tcp://auth@localhost:6379/2
106
+ You can omit the complete URI if you want to connect to the default address ` localhost:6379 ` :
107
+
108
+ ``` php
109
+ $factory->createClient();
110
+ ```
111
+
112
+ You can omit the port if you're connecting to the default port 6379:
113
+
114
+ ``` php
115
+ $factory->createClient('localhost');
116
+ ```
117
+
118
+ You can optionally include a password that will be used to authenticate (AUTH command) the client:
119
+
120
+ ``` php
121
+ $factory->createClient('auth@localhost');
122
+ ```
123
+
124
+ You can optionally include a path that will be used to select (SELECT command) the right database:
125
+
126
+ ``` php
127
+ $factory->createClient('localhost/2');
128
+ ```
108
129
109
130
### Client
110
131
0 commit comments