From 819f14610f364b041fbde040e4785c906ae16d0c Mon Sep 17 00:00:00 2001 From: yf <291323003@qq.com> Date: Sun, 16 Jun 2019 18:02:27 +0800 Subject: [PATCH] up --- src/Config.php | 43 +++++-------------------------------------- src/Connection.php | 3 ++- src/Redis.php | 11 ++--------- 3 files changed, 9 insertions(+), 48 deletions(-) diff --git a/src/Config.php b/src/Config.php index 76b9372..f32b085 100644 --- a/src/Config.php +++ b/src/Config.php @@ -8,12 +8,12 @@ class Config extends SplBean { - protected $host; - protected $port; + protected $host = '127.0.0.1'; + protected $port = 6379; protected $auth; - protected $options = []; - protected $serialize=false; - protected $timeout = 3; + protected $options = [ + 'serialize'=>true + ]; /** * @return mixed @@ -78,37 +78,4 @@ public function setOptions(array $options): void { $this->options = $options; } - - /** - * @return int - */ - public function getTimeout(): int - { - return $this->timeout; - } - - /** - * @param int $timeout - */ - public function setTimeout(int $timeout): void - { - $this->timeout = $timeout; - } - - /** - * @return bool - */ - public function getSerialize(): bool - { - return $this->serialize; - } - - /** - * @param bool $serialize - */ - public function setSerialize(bool $serialize): void - { - $this->serialize = $serialize; - } - } \ No newline at end of file diff --git a/src/Connection.php b/src/Connection.php index 78f4f2f..c40d22e 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -5,8 +5,9 @@ use EasySwoole\Component\Pool\PoolObjectInterface; +use Swoole\Coroutine\Redis; -class Connection extends \Swoole\Coroutine\Redis implements PoolObjectInterface +class Connection extends Redis implements PoolObjectInterface { function gc() { diff --git a/src/Redis.php b/src/Redis.php index 2dac576..8e32fd2 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -8,7 +8,6 @@ use EasySwoole\Component\Pool\PoolConf; use EasySwoole\Component\Pool\PoolManager; use EasySwoole\Component\Singleton; -use EasySwoole\RedisPool\RedisPoolException; use EasySwoole\Utility\Random; class Redis @@ -38,8 +37,8 @@ class '.$class.' extends AbstractPool { protected function createObject() { $config = $this->getConfig()->getExtraConf(); - $conn = new Connection(); - $ret = $conn->connect($config->getHost(),$config->getPort(),$config->getSerialize()); + $conn = new Connection($config->getOptions()); + $ret = $conn->connect($config->getHost(),$config->getPort()); if(!$ret){ return; } @@ -49,11 +48,6 @@ protected function createObject() if(!$ret){ return; } - if(!empty($config->getOptions())){ - foreach ($config->getOptions() as $key => $item){ - $conn->setOption($key,$item); - } - } return $conn; } }'; @@ -98,7 +92,6 @@ public function pool(string $name):?AbstractPool if($item instanceof AbstractPool){ return $item; }else{ - $class = $item['class']; $pool = PoolManager::getInstance()->getPool($class); $this->list[$name] = $pool;