Skip to content

Commit db30417

Browse files
committed
Better examples in documentation
1 parent 2795b0a commit db30417

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ local Redis server and send some requests:
4545
$loop = React\EventLoop\Factory::create();
4646
$factory = new Factory($loop);
4747

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', '!');
5151

52-
$client->GET('greeting')->then(function ($greeting) {
52+
$client->get('greeting')->then(function ($greeting) {
53+
// Hello world!
5354
echo $greeting . PHP_EOL;
5455
});
5556

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;
5859
});
5960

6061
// end connection once all pending requests have been resolved
@@ -87,24 +88,44 @@ $factory = new Factory($loop, $connector);
8788

8889
#### createClient()
8990

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).
9192
It helps with establishing a plain TCP/IP connection to Redis
9293
and optionally authenticating (AUTH) and selecting the right database (SELECT).
9394

9495
```php
95-
$factory->createClient('localhost')->then(
96+
$factory->createClient('localhost:6379')->then(
9697
function (Client $client) {
97-
// client connected and authenticated
98+
// client connected (and authenticated)
9899
},
99100
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
101102
}
102103
);
103104
```
104105

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+
```
108129

109130
### Client
110131

0 commit comments

Comments
 (0)