Skip to content

Commit

Permalink
Move RedisSocketException to Connection\RedisChannelException
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Aug 20, 2023
1 parent 5b408fa commit 758d594
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/Connection/ReconnectingRedisLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Amp\Future;
use Amp\Redis\Protocol\RedisResponse;
use Amp\Redis\RedisException;
use Amp\Redis\RedisSocketException;
use Revolt\EventLoop;

final class ReconnectingRedisLink implements RedisLink
Expand Down Expand Up @@ -121,7 +120,7 @@ private function run(): void
}
}
} catch (\Throwable $exception) {
$exception = new RedisSocketException($exception->getMessage(), 0, $exception);
$exception = new RedisChannelException($exception->getMessage(), 0, $exception);

while (!$queue->isEmpty()) {
/** @var DeferredFuture $deferred */
Expand Down
9 changes: 9 additions & 0 deletions src/Connection/RedisChannelException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace Amp\Redis\Connection;

use Amp\Redis\RedisException;

final class RedisChannelException extends RedisException
{
}
5 changes: 2 additions & 3 deletions src/Connection/SocketRedisChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Amp\Redis\Protocol\RedisResponse;
use Amp\Redis\Protocol\RespParser;
use Amp\Redis\RedisException;
use Amp\Redis\RedisSocketException;
use Amp\Socket\Socket;
use Revolt\EventLoop;

Expand Down Expand Up @@ -65,7 +64,7 @@ public function receive(): ?RedisResponse
public function send(string ...$args): void
{
if ($this->socket->isClosed()) {
throw new RedisSocketException('Redis connection already closed');
throw new RedisChannelException('Redis connection already closed');
}

$payload = \implode("\r\n", \array_map(fn (string $arg) => '$' . \strlen($arg) . "\r\n" . $arg, $args));
Expand All @@ -74,7 +73,7 @@ public function send(string ...$args): void
try {
$this->socket->write($payload);
} catch (StreamException $e) {
throw new RedisSocketException($e->getMessage(), 0, $e);
throw new RedisChannelException($e->getMessage(), 0, $e);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/Connection/SocketRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Redis\RedisException;
use Amp\Redis\RedisSocketException;
use Amp\Socket;
use Amp\Socket\ConnectContext;
use Amp\Socket\SocketConnector;
Expand All @@ -30,15 +29,15 @@ public function __construct(
/**
* @throws CancelledException
* @throws RedisException
* @throws RedisSocketException
* @throws RedisChannelException
*/
public function connect(?Cancellation $cancellation = null): RedisChannel
{
try {
$socketConnector = $this->socketConnector ?? Socket\socketConnector();
$socket = $socketConnector->connect($this->uri, $this->connectContext, $cancellation);
} catch (Socket\SocketException $e) {
throw new RedisSocketException(
throw new RedisChannelException(
'Failed to connect to redis instance (' . $this->uri . ')',
0,
$e
Expand Down
7 changes: 0 additions & 7 deletions src/RedisSocketException.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/RedisSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Amp\Future;
use Amp\Pipeline\Queue;
use Amp\Redis\Connection\RedisChannel;
use Amp\Redis\Connection\RedisChannelException;
use Amp\Redis\Connection\RedisConnector;
use Revolt\EventLoop;
use function Amp\async;
Expand Down Expand Up @@ -144,7 +145,7 @@ private function run(): void
}
}
} catch (\Throwable $exception) {
$exception = new RedisSocketException($exception->getMessage(), 0, $exception);
$exception = new RedisChannelException($exception->getMessage(), 0, $exception);

$queueGroups = \array_merge($queues, $patternQueues);

Expand Down
3 changes: 2 additions & 1 deletion test/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Amp\PHPUnit\AsyncTestCase;
use Amp\Process\Process;
use Amp\Redis\Command\RedisCommands;
use Amp\Redis\Connection\RedisChannelException;
use function Amp\delay;

class AuthTest extends AsyncTestCase
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testFailure(): void
{
$redis = new RedisCommands(createRedisClient(\sprintf(self::URI_FORMAT, self::PORT, 'wrong')));

$this->expectException(RedisSocketException::class);
$this->expectException(RedisChannelException::class);

$this->expectExceptionMessage('invalid');

Expand Down
3 changes: 2 additions & 1 deletion test/DownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use Amp\PHPUnit\AsyncTestCase;
use Amp\Redis\Command\RedisCommands;
use Amp\Redis\Connection\RedisChannelException;

class DownTest extends AsyncTestCase
{
public function test(): void
{
$this->expectException(RedisSocketException::class);
$this->expectException(RedisChannelException::class);

$redis = new RedisCommands(createRedisClient('tcp://127.0.0.1:25325'));
$redis->ping();
Expand Down

0 comments on commit 758d594

Please sign in to comment.