Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting, include Redis URI and socket error codes in all connection errors #116

Merged
merged 4 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ local Redis server and send some requests:

```php
$factory = new Clue\React\Redis\Factory();
$client = $factory->createLazyClient('localhost:6379');

$client = $factory->createLazyClient('localhost');
$client->set('greeting', 'Hello world');
$client->append('greeting', '!');

Expand Down Expand Up @@ -118,14 +118,14 @@ $factory = new Clue\React\Redis\Factory(null, $connector);

#### createClient()

The `createClient(string $redisUri): PromiseInterface<Client,Exception>` method can be used to
The `createClient(string $uri): PromiseInterface<Client,Exception>` method can be used to
create a new [`Client`](#client).

It helps with establishing a plain TCP/IP or secure TLS connection to Redis
and optionally authenticating (AUTH) and selecting the right database (SELECT).

```php
$factory->createClient('redis://localhost:6379')->then(
$factory->createClient('localhost:6379')->then(
function (Client $client) {
// client connected (and authenticated)
},
Expand All @@ -146,7 +146,7 @@ reject its value with an Exception and will cancel the underlying TCP/IP
connection attempt and/or Redis authentication.

```php
$promise = $factory->createClient($redisUri);
$promise = $factory->createClient($uri);

Loop::addTimer(3.0, function () use ($promise) {
$promise->cancel();
Expand Down Expand Up @@ -215,14 +215,14 @@ $factory->createClient('localhost?timeout=0.5');

#### createLazyClient()

The `createLazyClient(string $redisUri): Client` method can be used to
The `createLazyClient(string $uri): Client` method can be used to
create a new [`Client`](#client).

It helps with establishing a plain TCP/IP or secure TLS connection to Redis
and optionally authenticating (AUTH) and selecting the right database (SELECT).

```php
$client = $factory->createLazyClient('redis://localhost:6379');
$client = $factory->createLazyClient('localhost:6379');

$client->incr('hello');
$client->end();
Expand Down
14 changes: 7 additions & 7 deletions examples/cli.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

// $ php examples/cli.php
// $ REDIS_URI=localhost:6379 php examples/cli.php

use Clue\React\Redis\Client;
use Clue\React\Redis\Factory;
use React\EventLoop\Loop;
Expand All @@ -11,7 +14,7 @@

echo '# connecting to redis...' . PHP_EOL;

$factory->createClient('localhost')->then(function (Client $client) {
$factory->createClient(getenv('REDIS_URI') ?: 'localhost:6379')->then(function (Client $client) {
echo '# connected! Entering interactive mode, hit CTRL-D to quit' . PHP_EOL;

Loop::addReadStream(STDIN, function () use ($client) {
Expand All @@ -38,7 +41,7 @@

$promise->then(function ($data) {
echo '# reply: ' . json_encode($data) . PHP_EOL;
}, function ($e) {
}, function (Exception $e) {
echo '# error reply: ' . $e->getMessage() . PHP_EOL;
});
});
Expand All @@ -48,10 +51,7 @@

Loop::removeReadStream(STDIN);
});
}, function (Exception $error) {
echo 'CONNECTION ERROR: ' . $error->getMessage() . PHP_EOL;
if ($error->getPrevious()) {
echo $error->getPrevious()->getMessage() . PHP_EOL;
}
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
exit(1);
});
10 changes: 5 additions & 5 deletions examples/incr.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

// $ php examples/incr.php
// $ REDIS_URI=localhost:6379 php examples/incr.php

use Clue\React\Redis\Factory;

require __DIR__ . '/../vendor/autoload.php';

$factory = new Factory();
$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');

$client = $factory->createLazyClient('localhost');
$client->incr('test');

$client->get('test')->then(function ($result) {
var_dump($result);
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
if ($e->getPrevious()) {
echo $e->getPrevious()->getMessage() . PHP_EOL;
}
exit(1);
});

$client->end();
//$client->end();
8 changes: 4 additions & 4 deletions examples/publish.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php

// $ php examples/publish.php
// $ REDIS_URI=localhost:6379 php examples/publish.php channel message

use Clue\React\Redis\Factory;

require __DIR__ . '/../vendor/autoload.php';

$factory = new Factory();
$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');

$channel = isset($argv[1]) ? $argv[1] : 'channel';
$message = isset($argv[2]) ? $argv[2] : 'message';

$client = $factory->createLazyClient('localhost');
$client->publish($channel, $message)->then(function ($received) {
echo 'Successfully published. Received by ' . $received . PHP_EOL;
}, function (Exception $e) {
echo 'Unable to publish: ' . $e->getMessage() . PHP_EOL;
if ($e->getPrevious()) {
echo $e->getPrevious()->getMessage() . PHP_EOL;
}
exit(1);
});

Expand Down
5 changes: 4 additions & 1 deletion examples/subscribe.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?php

// $ php examples/subscribe.php
// $ REDIS_URI=localhost:6379 php examples/subscribe.php channel

use Clue\React\Redis\Factory;
use React\EventLoop\Loop;

require __DIR__ . '/../vendor/autoload.php';

$factory = new Factory();
$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379');

$channel = isset($argv[1]) ? $argv[1] : 'channel';

$client = $factory->createLazyClient('localhost');
$client->subscribe($channel)->then(function () {
echo 'Now subscribed to channel ' . PHP_EOL;
}, function (Exception $e) use ($client) {
Expand Down
Loading