From ba28a1a25bb5bc38b0a223ae9c8ac80cfcdcfba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 3 Sep 2020 18:05:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/Cache/Redis.php | 4 ++++ system/Exception/RedisConnectException.php | 10 ++++++++++ system/Pool/Redis.php | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 system/Exception/RedisConnectException.php diff --git a/system/Cache/Redis.php b/system/Cache/Redis.php index 8ce787d8..21e91990 100644 --- a/system/Cache/Redis.php +++ b/system/Cache/Redis.php @@ -13,6 +13,7 @@ use Snowflake\Abstracts\Component; use Snowflake\Config; use Snowflake\Event; use Snowflake\Exception\ConfigException; +use Snowflake\Exception\RedisConnectException; use Snowflake\Snowflake; use Swoole\Coroutine; @@ -284,6 +285,9 @@ class Redis extends Component $data = $this->proxy()->{$name}(...$arguments); } } catch (\Throwable $exception) { + if ($exception instanceof RedisConnectException) { + throw new Exception($exception->getMessage()); + } $this->error(print_r($exception, true)); $data = false; } finally { diff --git a/system/Exception/RedisConnectException.php b/system/Exception/RedisConnectException.php new file mode 100644 index 00000000..6e54094f --- /dev/null +++ b/system/Exception/RedisConnectException.php @@ -0,0 +1,10 @@ +connect($config['host'], $config['port'], $config['timeout'])) { - throw new Exception(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port'])); + throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port'])); } if (empty($config['auth']) || !$redis->auth($config['auth'])) { - throw new Exception(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth'])); + throw new RedisConnectException(sprintf('Redis Error: %s, Host %s, Auth %s', $redis->getLastError(), $config['host'], $config['auth'])); } if (!isset($config['read_timeout'])) { $config['read_timeout'] = 10;