@@ -63,22 +63,22 @@ local Redis server and send some requests:
63
63
64
64
``` php
65
65
$factory = new Clue\React\Redis\Factory();
66
- $client = $factory->createLazyClient('localhost:6379');
66
+ $redis = $factory->createLazyClient('localhost:6379');
67
67
68
- $client ->set('greeting', 'Hello world');
69
- $client ->append('greeting', '!');
68
+ $redis ->set('greeting', 'Hello world');
69
+ $redis ->append('greeting', '!');
70
70
71
- $client ->get('greeting')->then(function ($greeting) {
71
+ $redis ->get('greeting')->then(function ($greeting) {
72
72
// Hello world!
73
73
echo $greeting . PHP_EOL;
74
74
});
75
75
76
- $client ->incr('invocation')->then(function ($n) {
76
+ $redis ->incr('invocation')->then(function ($n) {
77
77
echo 'This is invocation #' . $n . PHP_EOL;
78
78
});
79
79
80
80
// end connection once all pending requests have been resolved
81
- $client ->end();
81
+ $redis ->end();
82
82
```
83
83
84
84
See also the [ examples] ( examples ) .
@@ -91,20 +91,20 @@ Most importantly, this project provides a [`Client`](#client) instance that
91
91
can be used to invoke all [ Redis commands] ( https://redis.io/commands ) (such as ` GET ` , ` SET ` , etc.).
92
92
93
93
``` 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);
99
99
100
- $client ->multi();
101
- $client ->exec();
100
+ $redis ->multi();
101
+ $redis ->exec();
102
102
103
- $client ->publish($channel, $payload);
104
- $client ->subscribe($channel);
103
+ $redis ->publish($channel, $payload);
104
+ $redis ->subscribe($channel);
105
105
106
- $client ->ping();
107
- $client ->select($database);
106
+ $redis ->ping();
107
+ $redis ->select($database);
108
108
109
109
// many more…
110
110
```
@@ -161,17 +161,17 @@ send a message to all clients currently subscribed to a given channel:
161
161
``` php
162
162
$channel = 'user';
163
163
$message = json_encode(array('id' => 10));
164
- $client ->publish($channel, $message);
164
+ $redis ->publish($channel, $message);
165
165
```
166
166
167
167
The [ ` SUBSCRIBE ` command] ( https://redis.io/commands/subscribe ) can be used to
168
168
subscribe to a channel and then receive incoming PubSub ` message ` events:
169
169
170
170
``` php
171
171
$channel = 'user';
172
- $client ->subscribe($channel);
172
+ $redis ->subscribe($channel);
173
173
174
- $client ->on('message', function ($channel, $payload) {
174
+ $redis ->on('message', function ($channel, $payload) {
175
175
// pubsub message received on given $channel
176
176
var_dump($channel, json_decode($payload));
177
177
});
@@ -181,9 +181,9 @@ Likewise, you can use the same client connection to subscribe to multiple
181
181
channels by simply executing this command multiple times:
182
182
183
183
``` 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');
187
187
```
188
188
189
189
Similarly, the [ ` PSUBSCRIBE ` command] ( https://redis.io/commands/psubscribe ) can
@@ -193,9 +193,9 @@ all incoming PubSub messages with the `pmessage` event:
193
193
194
194
``` php
195
195
$pattern = 'user.*';
196
- $client ->psubscribe($pattern);
196
+ $redis ->psubscribe($pattern);
197
197
198
- $client ->on('pmessage', function ($pattern, $channel, $payload) {
198
+ $redis ->on('pmessage', function ($pattern, $channel, $payload) {
199
199
// pubsub message received matching given $pattern
200
200
var_dump($channel, json_decode($payload));
201
201
});
@@ -213,10 +213,10 @@ receiving any further events for the given channel and pattern subscriptions
213
213
respectively:
214
214
215
215
``` php
216
- $client ->subscribe('user');
216
+ $redis ->subscribe('user');
217
217
218
- Loop::addTimer(60.0, function () use ($client ) {
219
- $client ->unsubscribe('user');
218
+ Loop::addTimer(60.0, function () use ($redis ) {
219
+ $redis ->unsubscribe('user');
220
220
});
221
221
```
222
222
@@ -235,16 +235,16 @@ Additionally, can listen for the following PubSub events to get notifications
235
235
about subscribed/unsubscribed channels and patterns:
236
236
237
237
``` php
238
- $client ->on('subscribe', function ($channel, $total) {
238
+ $redis ->on('subscribe', function ($channel, $total) {
239
239
// subscribed to given $channel
240
240
});
241
- $client ->on('psubscribe', function ($pattern, $total) {
241
+ $redis ->on('psubscribe', function ($pattern, $total) {
242
242
// subscribed to matching given $pattern
243
243
});
244
- $client ->on('unsubscribe', function ($channel, $total) {
244
+ $redis ->on('unsubscribe', function ($channel, $total) {
245
245
// unsubscribed from given $channel
246
246
});
247
- $client ->on('punsubscribe', function ($pattern, $total) {
247
+ $redis ->on('punsubscribe', function ($pattern, $total) {
248
248
// unsubscribed from matching given $pattern
249
249
});
250
250
```
@@ -299,7 +299,7 @@ and optionally authenticating (AUTH) and selecting the right database (SELECT).
299
299
300
300
``` php
301
301
$factory->createClient('localhost:6379')->then(
302
- function (Client $client ) {
302
+ function (Client $redis ) {
303
303
// client connected (and authenticated)
304
304
},
305
305
function (Exception $e) {
@@ -395,10 +395,10 @@ It helps with establishing a plain TCP/IP or secure TLS connection to Redis
395
395
and optionally authenticating (AUTH) and selecting the right database (SELECT).
396
396
397
397
``` php
398
- $client = $factory->createLazyClient('localhost:6379');
398
+ $redis = $factory->createLazyClient('localhost:6379');
399
399
400
- $client ->incr('hello');
401
- $client ->end();
400
+ $redis ->incr('hello');
401
+ $redis ->end();
402
402
```
403
403
404
404
This method immediately returns a "virtual" connection implementing the
@@ -576,7 +576,7 @@ when the client connection is lost or is invalid.
576
576
The event receives a single ` Exception ` argument for the error instance.
577
577
578
578
``` php
579
- $client ->on('error', function (Exception $e) {
579
+ $redis ->on('error', function (Exception $e) {
580
580
echo 'Error: ' . $e->getMessage() . PHP_EOL;
581
581
});
582
582
```
@@ -590,7 +590,7 @@ errors caused by invalid commands.
590
590
The ` close ` event will be emitted once the client connection closes (terminates).
591
591
592
592
``` php
593
- $client ->on('close', function () {
593
+ $redis ->on('close', function () {
594
594
echo 'Connection closed' . PHP_EOL;
595
595
});
596
596
```
0 commit comments