@@ -53,6 +53,8 @@ $loop->run();
53
53
54
54
See also the [ examples] ( examples ) .
55
55
56
+ ## Usage
57
+
56
58
### Factory
57
59
58
60
The ` Factory ` is responsible for creating your ` Client ` instance.
@@ -87,6 +89,40 @@ $factory->createClient('localhost')->then(
87
89
The ` Client ` is responsible for exchanging messages with Redis
88
90
and keeps track of pending commands.
89
91
92
+ All [ Redis commands] ( http://redis.io/commands ) are automatically available as public methods (via the magic ` __call() ` method) like this:
93
+
94
+ ``` php
95
+ $client->get($key);
96
+ $client->set($key, $value);
97
+ $client->exists($key);
98
+ $client->expire($key, $seconds);
99
+ $client->mget($key1, $key2, $key3);
100
+
101
+ $client->multi();
102
+ $client->exec();
103
+
104
+ $client->publish($channel, $payload);
105
+ $client->subscribe($channel);
106
+
107
+ $client->ping();
108
+ $client->select($database);
109
+ ```
110
+
111
+ Listing all available commands is out of scope here, please refer to the [ Redis command reference] ( http://redis.io/commands ) .
112
+
113
+ Sending commands is async (non-blocking), so you can actually send multiple commands in parallel.
114
+ Redis will respond to each command request with a response message, pending commands will be pipelined automatically.
115
+ Sending commands uses a [ Promise] ( https://github.com/reactphp/promise ) -based interface that makes it easy to react to when a command is * fulfilled*
116
+ (i.e. either successfully resolved or rejected with an error):
117
+
118
+ ``` php
119
+ $client->set('hello', 'world');
120
+ $client->get('hello')->then(function ($response) {
121
+ // response received for GET command
122
+ echo 'hello ' . $response;
123
+ });
124
+ ```
125
+
90
126
The ` on($eventName, $eventHandler) ` method can be used to register a new event handler.
91
127
Incoming events and errors will be forwarded to registered event handler callbacks:
92
128
@@ -128,40 +164,6 @@ $client->on('monitor', function (StatusReply $message) {
128
164
});
129
165
```
130
166
131
- Sending commands is async (non-blocking), so you can actually send multiple commands in parallel.
132
- Redis will respond to each command request with a response message.
133
- Sending commands uses a Promise-based interface that makes it easy to react to when a command is * fulfilled*
134
- (i.e. either successfully resolved or rejected with an error):
135
-
136
- ``` php
137
- $client->set('hello', 'world');
138
- $client->get('hello')->then(function ($response) {
139
- // response received for GET command
140
- echo 'hello ' . $response;
141
- });
142
- ```
143
-
144
- All [ Redis commands] ( http://redis.io/commands ) are automatically available as public methods (via the magic ` __call() ` method) like this:
145
-
146
- ``` php
147
- $client->get($key);
148
- $client->set($key, $value);
149
- $client->exists($key);
150
- $client->expire($key, $seconds);
151
- $client->mget($key1, $key2, $key3);
152
-
153
- $client->multi();
154
- $client->exec();
155
-
156
- $client->publish($channel, $payload);
157
- $client->subscribe($channel);
158
-
159
- $client->ping();
160
- $client->select($database);
161
- ```
162
-
163
- Listing all available commands is out of scope here, please refer to the [ Redis command reference] ( http://redis.io/commands ) .
164
-
165
167
The ` close() ` method can be used to force-close the Redis connection and reject all pending commands.
166
168
167
169
The ` end() ` method can be used to soft-close the Redis connection once all pending commands are completed.
0 commit comments