Skip to content

Commit fea3e69

Browse files
committed
Optimized code.
1 parent 38c0a97 commit fea3e69

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://doc.hyperf.io
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
312

413
namespace Hyperf\Redis\Exception;
514

15+
use RuntimeException;
616

7-
class InvalidRedisConnectionException
17+
class InvalidRedisConnectionException extends RuntimeException
818
{
9-
10-
}
19+
}

src/Redis.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hyperf\Redis;
1414

15+
use Hyperf\Redis\Exception\InvalidRedisConnectionException;
1516
use Hyperf\Redis\Pool\PoolFactory;
1617
use Hyperf\Utils\Context;
1718

@@ -89,7 +90,10 @@ private function getConnection($hasContextConnection): RedisConnection
8990
}
9091
if (! $connection instanceof RedisConnection) {
9192
$pool = $this->factory->getPool($this->poolName);
92-
return $pool->get();
93+
$connection = $pool->get();
94+
}
95+
if (! $connection instanceof RedisConnection) {
96+
throw new InvalidRedisConnectionException('The connection is not a valid RedisConnection.');
9397
}
9498
return $connection;
9599
}

0 commit comments

Comments
 (0)