@@ -63,22 +63,22 @@ local Redis server and send some requests:
6363
6464``` php
6565$factory = new Clue\React\Redis\Factory();
66- $client = $factory->createLazyClient('localhost:6379');
66+ $redis = $factory->createLazyClient('localhost:6379');
6767
68- $client ->set('greeting', 'Hello world');
69- $client ->append('greeting', '!');
68+ $redis ->set('greeting', 'Hello world');
69+ $redis ->append('greeting', '!');
7070
71- $client ->get('greeting')->then(function ($greeting) {
71+ $redis ->get('greeting')->then(function ($greeting) {
7272 // Hello world!
7373 echo $greeting . PHP_EOL;
7474});
7575
76- $client ->incr('invocation')->then(function ($n) {
76+ $redis ->incr('invocation')->then(function ($n) {
7777 echo 'This is invocation #' . $n . PHP_EOL;
7878});
7979
8080// end connection once all pending requests have been resolved
81- $client ->end();
81+ $redis ->end();
8282```
8383
8484See also the [ examples] ( examples ) .
@@ -91,20 +91,20 @@ Most importantly, this project provides a [`Client`](#client) instance that
9191can be used to invoke all [ Redis commands] ( https://redis.io/commands ) (such as ` GET ` , ` SET ` , etc.).
9292
9393``` php
94- $client ->get($key);
95- $client ->set($key, $value);
96- $client ->exists($key);
97- $client ->expire($key, $seconds);
98- $client ->mget($key1, $key2, $key3);
94+ $redis ->get($key);
95+ $redis ->set($key, $value);
96+ $redis ->exists($key);
97+ $redis ->expire($key, $seconds);
98+ $redis ->mget($key1, $key2, $key3);
9999
100- $client ->multi();
101- $client ->exec();
100+ $redis ->multi();
101+ $redis ->exec();
102102
103- $client ->publish($channel, $payload);
104- $client ->subscribe($channel);
103+ $redis ->publish($channel, $payload);
104+ $redis ->subscribe($channel);
105105
106- $client ->ping();
107- $client ->select($database);
106+ $redis ->ping();
107+ $redis ->select($database);
108108
109109// many more…
110110```
@@ -161,17 +161,17 @@ send a message to all clients currently subscribed to a given channel:
161161``` php
162162$channel = 'user';
163163$message = json_encode(array('id' => 10));
164- $client ->publish($channel, $message);
164+ $redis ->publish($channel, $message);
165165```
166166
167167The [ ` SUBSCRIBE ` command] ( https://redis.io/commands/subscribe ) can be used to
168168subscribe to a channel and then receive incoming PubSub ` message ` events:
169169
170170``` php
171171$channel = 'user';
172- $client ->subscribe($channel);
172+ $redis ->subscribe($channel);
173173
174- $client ->on('message', function ($channel, $payload) {
174+ $redis ->on('message', function ($channel, $payload) {
175175 // pubsub message received on given $channel
176176 var_dump($channel, json_decode($payload));
177177});
@@ -181,9 +181,9 @@ Likewise, you can use the same client connection to subscribe to multiple
181181channels by simply executing this command multiple times:
182182
183183``` php
184- $client ->subscribe('user.register');
185- $client ->subscribe('user.join');
186- $client ->subscribe('user.leave');
184+ $redis ->subscribe('user.register');
185+ $redis ->subscribe('user.join');
186+ $redis ->subscribe('user.leave');
187187```
188188
189189Similarly, the [ ` PSUBSCRIBE ` command] ( https://redis.io/commands/psubscribe ) can
@@ -193,9 +193,9 @@ all incoming PubSub messages with the `pmessage` event:
193193
194194``` php
195195$pattern = 'user.*';
196- $client ->psubscribe($pattern);
196+ $redis ->psubscribe($pattern);
197197
198- $client ->on('pmessage', function ($pattern, $channel, $payload) {
198+ $redis ->on('pmessage', function ($pattern, $channel, $payload) {
199199 // pubsub message received matching given $pattern
200200 var_dump($channel, json_decode($payload));
201201});
@@ -213,10 +213,10 @@ receiving any further events for the given channel and pattern subscriptions
213213respectively:
214214
215215``` php
216- $client ->subscribe('user');
216+ $redis ->subscribe('user');
217217
218- Loop::addTimer(60.0, function () use ($client ) {
219- $client ->unsubscribe('user');
218+ Loop::addTimer(60.0, function () use ($redis ) {
219+ $redis ->unsubscribe('user');
220220});
221221```
222222
@@ -235,16 +235,16 @@ Additionally, can listen for the following PubSub events to get notifications
235235about subscribed/unsubscribed channels and patterns:
236236
237237``` php
238- $client ->on('subscribe', function ($channel, $total) {
238+ $redis ->on('subscribe', function ($channel, $total) {
239239 // subscribed to given $channel
240240});
241- $client ->on('psubscribe', function ($pattern, $total) {
241+ $redis ->on('psubscribe', function ($pattern, $total) {
242242 // subscribed to matching given $pattern
243243});
244- $client ->on('unsubscribe', function ($channel, $total) {
244+ $redis ->on('unsubscribe', function ($channel, $total) {
245245 // unsubscribed from given $channel
246246});
247- $client ->on('punsubscribe', function ($pattern, $total) {
247+ $redis ->on('punsubscribe', function ($pattern, $total) {
248248 // unsubscribed from matching given $pattern
249249});
250250```
@@ -299,7 +299,7 @@ and optionally authenticating (AUTH) and selecting the right database (SELECT).
299299
300300``` php
301301$factory->createClient('localhost:6379')->then(
302- function (Client $client ) {
302+ function (Client $redis ) {
303303 // client connected (and authenticated)
304304 },
305305 function (Exception $e) {
@@ -395,10 +395,10 @@ It helps with establishing a plain TCP/IP or secure TLS connection to Redis
395395and optionally authenticating (AUTH) and selecting the right database (SELECT).
396396
397397``` php
398- $client = $factory->createLazyClient('localhost:6379');
398+ $redis = $factory->createLazyClient('localhost:6379');
399399
400- $client ->incr('hello');
401- $client ->end();
400+ $redis ->incr('hello');
401+ $redis ->end();
402402```
403403
404404This method immediately returns a "virtual" connection implementing the
@@ -576,7 +576,7 @@ when the client connection is lost or is invalid.
576576The event receives a single ` Exception ` argument for the error instance.
577577
578578``` php
579- $client ->on('error', function (Exception $e) {
579+ $redis ->on('error', function (Exception $e) {
580580 echo 'Error: ' . $e->getMessage() . PHP_EOL;
581581});
582582```
@@ -590,7 +590,7 @@ errors caused by invalid commands.
590590The ` close ` event will be emitted once the client connection closes (terminates).
591591
592592``` php
593- $client ->on('close', function () {
593+ $redis ->on('close', function () {
594594 echo 'Connection closed' . PHP_EOL;
595595});
596596```
0 commit comments