Skip to content

Commit abe5232

Browse files
committed
Update README.md
1 parent 5f13146 commit abe5232

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

README.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ $loop->run();
5353

5454
See also the [examples](examples).
5555

56+
## Usage
57+
5658
### Factory
5759

5860
The `Factory` is responsible for creating your `Client` instance.
@@ -87,6 +89,40 @@ $factory->createClient('localhost')->then(
8789
The `Client` is responsible for exchanging messages with Redis
8890
and keeps track of pending commands.
8991

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+
90126
The `on($eventName, $eventHandler)` method can be used to register a new event handler.
91127
Incoming events and errors will be forwarded to registered event handler callbacks:
92128

@@ -128,40 +164,6 @@ $client->on('monitor', function (StatusReply $message) {
128164
});
129165
```
130166

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-
165167
The `close()` method can be used to force-close the Redis connection and reject all pending commands.
166168

167169
The `end()` method can be used to soft-close the Redis connection once all pending commands are completed.

0 commit comments

Comments
 (0)