From 83202fb9fc18c72a0c2b39dd9f1dad42e0754bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 10:48:03 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA=20ma?= =?UTF-8?q?c=20=E4=B8=8A=E7=9A=84=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/debugTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index 6d3e901d..5be45de2 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -166,6 +166,8 @@ class debugTest extends \PHPUnit_Framework_TestCase $array = explode("array", json_encode($output)); if (IS_WIN) { $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array)); + } else if (IS_MAC) { + $this->assertEquals("(1) {\\n [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); } else { $this->assertEquals("(1) {\\n 'key' =>\\n string(3) \\\"val\\\"\\n}\\n\\n\"", end($array)); } From caf86af6b20d77141e2007771fc759040bbb65c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 11:10:23 +0800 Subject: [PATCH 02/10] fix Undefined variable: value --- library/think/cache/driver/Redisd.php | 1 + library/think/session/driver/Redis.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/think/cache/driver/Redisd.php b/library/think/cache/driver/Redisd.php index f4ac7281..dbfdafad 100644 --- a/library/think/cache/driver/Redisd.php +++ b/library/think/cache/driver/Redisd.php @@ -200,6 +200,7 @@ class Redisd { $this->master(false); + $value = null; try { $value = $this->handler->get($this->options['prefix'] . $name); } catch (\RedisException $e) { diff --git a/library/think/session/driver/Redis.php b/library/think/session/driver/Redis.php index 23bdfb77..b07289dd 100644 --- a/library/think/session/driver/Redis.php +++ b/library/think/session/driver/Redis.php @@ -45,11 +45,11 @@ class Redis extends SessionHandler throw new Exception('_NOT_SUPPERT_:redis'); } $this->handler = new \Redis; + // 建立连接 $func = $this->config['persistent'] ? 'pconnect' : 'connect'; - $this->config['timeout'] > 0 ? - $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']) : - $this->handler->$func($this->config['host'], $this->config['port']); + $this->handler->$func($this->config['host'], $this->config['port'], $this->config['timeout']); + if ('' != $this->config['password']) { $this->handler->auth($this->config['password']); } From cb7f4e8d57829f0405be9f18cfccf4a23c21b0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 23:29:06 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E5=A4=84redis?= =?UTF-8?q?d=20master=20=E8=BF=94=E5=9B=9E=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redisd.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/Redisd.php b/library/think/cache/driver/Redisd.php index dbfdafad..426f594e 100644 --- a/library/think/cache/driver/Redisd.php +++ b/library/think/cache/driver/Redisd.php @@ -111,7 +111,8 @@ class Redisd public function master($master = false) { if (isset(self::$redis_rw_handler[$master])) { - return $this->handler = self::$redis_rw_handler[$master]; + $this->handler = self::$redis_rw_handler[$master]; + return $this; } //如果不为主,则从配置的host剔除主,并随机读从,失败以后再随机选择从 @@ -186,7 +187,8 @@ class Redisd throw new Exception($e->getMessage(), $e->getCode()); } - return self::$redis_rw_handler[$master] = $this->handler; + self::$redis_rw_handler[$master] = $this->handler; + return $this; } /** From fb420d5acfea6668816ddac21f3c67338cafe304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 23:32:18 +0800 Subject: [PATCH 04/10] =?UTF-8?q?redisd=20get=E6=96=B9=E6=B3=95=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E6=8C=87=E5=AE=9A=E4=B8=BB=E4=BB=8E=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redisd.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/Redisd.php b/library/think/cache/driver/Redisd.php index 426f594e..5e08dcd2 100644 --- a/library/think/cache/driver/Redisd.php +++ b/library/think/cache/driver/Redisd.php @@ -198,9 +198,9 @@ class Redisd * @param string $name 缓存key * @return mixed */ - public function get($name) + public function get($name, $master = false) { - $this->master(false); + $this->master($master); $value = null; try { From 2dd7e7ef20e2986cec8847748682d94632de8528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 23:37:39 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E5=AE=8C=E5=96=84redisd=E7=9A=84?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/think/cache/driver/redisdTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/thinkphp/library/think/cache/driver/redisdTest.php b/tests/thinkphp/library/think/cache/driver/redisdTest.php index 96541299..c32264a7 100644 --- a/tests/thinkphp/library/think/cache/driver/redisdTest.php +++ b/tests/thinkphp/library/think/cache/driver/redisdTest.php @@ -46,19 +46,19 @@ class redisdTest extends cacheTestCase public function testStoreSpecialValues() { - $redis = new \think\cache\driver\Redisd(['length' => 3]); + $redis = $this->getCacheInstance(); $redis->master(true); $redis->handler()->setnx('key', 'value'); $value = $redis->handler()->get('key'); $this->assertEquals('value', $value); - $redis->handler()->hset('hash', 'key', 'value'); - $value = $redis->handler()->hget('hash', 'key'); - $this->assertEquals('value', $value); + $redis->master(true)->set('key', 'val'); + $value = $redis->master(false)->get('key'); + $this->assertEquals('val', $value); - $redis->master(true)->hset('hash', 'key', 'value'); - $value = $redis->master(false)->hget('hash', 'key'); + $redis->handler(true)->hset('hash', 'key', 'value'); + $value = $redis->handler(false)->hget('hash', 'key'); $this->assertEquals('value', $value); } From 2fcd752d33a904d7aa46cb218be496ae0a778e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 23:43:47 +0800 Subject: [PATCH 06/10] =?UTF-8?q?redisd=20handler=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=8C=87=E5=AE=9A=E4=B8=BB=E4=BB=8E=E8=8A=82?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redisd.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/cache/driver/Redisd.php b/library/think/cache/driver/Redisd.php index 5e08dcd2..a951888b 100644 --- a/library/think/cache/driver/Redisd.php +++ b/library/think/cache/driver/Redisd.php @@ -196,6 +196,7 @@ class Redisd * * @access public * @param string $name 缓存key + * @param bool $master 指定主从节点,可以从主节点获取结果 * @return mixed */ public function get($name, $master = false) @@ -301,10 +302,12 @@ class Redisd * 需要先执行 $redis->master() 连接到 DB * * @access public + * @param bool $master 指定主从节点,可以从主节点获取结果 * @return object */ - public function handler() + public function handler($master = true) { + $this->master($master); return $this->handler; } From 72a45d6a8d94bda7143cc2abfa0ec74095321aa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 23:55:20 +0800 Subject: [PATCH 07/10] =?UTF-8?q?hhvm=E4=B8=8Bdebug=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=BC=82=E5=B8=B8=EF=BC=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95ok=EF=BC=8C=E6=9A=82=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/debugTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index 5be45de2..90c5cb93 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -33,6 +33,10 @@ class debugTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { + if (strstr(PHP_VERSION, 'hhvm')) { + $this->markTestSkipped("HHVM下跳过测试"); + } + $this->object = new Debug(); } From 6786e8d9ab220be5152777519ed7a2c2f47bd78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Mon, 9 May 2016 18:06:45 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BC=98=E5=8C=96hhvm=E4=B8=8Bsession?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/sessionTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/thinkphp/library/think/sessionTest.php b/tests/thinkphp/library/think/sessionTest.php index e8f1436c..50ae99b6 100644 --- a/tests/thinkphp/library/think/sessionTest.php +++ b/tests/thinkphp/library/think/sessionTest.php @@ -122,7 +122,11 @@ class sessionTest extends \PHPUnit_Framework_TestCase // PHP_SESSION_NONE // PHP_SESSION_ACTIVE // session_status() - $this->assertEquals(0, ini_get('session.auto_start')); + if (strstr(PHP_VERSION, 'hhvm')) { + $this->assertEquals('', ini_get('session.auto_start')); + }else{ + $this->assertEquals(0, ini_get('session.auto_start')); + } $this->assertEquals($config['use_trans_sid'], ini_get('session.use_trans_sid')); From 6d46bf327613c33555b8f3d9957302f64282a60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Mon, 9 May 2016 19:37:02 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E9=83=A8=E5=88=86=E9=87=8D=E6=9E=84Redis?= =?UTF-8?q?d=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redisd.php | 62 ++++++++++++--------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/library/think/cache/driver/Redisd.php b/library/think/cache/driver/Redisd.php index a951888b..67058975 100644 --- a/library/think/cache/driver/Redisd.php +++ b/library/think/cache/driver/Redisd.php @@ -72,6 +72,7 @@ class Redisd 'persistent' => false, 'length' => 0, 'prefix' => '', + 'serialize' => \Redis::SERIALIZER_PHP, ]; /** @@ -106,9 +107,10 @@ class Redisd * 一致Hash适合超高可用,跨网络读取,且从节点较多的情况,本业务不考虑该需求 * * @access public - * @param bool $master true 默认主写 + * @param bool $master true 默认主写 + * @return Redisd */ - public function master($master = false) + public function master($master = true) { if (isset(self::$redis_rw_handler[$master])) { $this->handler = self::$redis_rw_handler[$master]; @@ -131,17 +133,23 @@ class Redisd $host = isset($parse['host']) ? $parse['host'] : $host; $port = isset($parse['host']) ? $parse['port'] : $this->options['port']; - $this->handler->$func($host, $port, $this->options['timeout']); - - if (null != $this->options['password']) { - $this->handler->auth($this->options['password']); - } - - APP_DEBUG && Log::record("[ CACHE ] INIT Redisd : {$host}:{$port} master->" . var_export($master, true), 'info'); - //发生错误则摘掉当前节点 try { - $error = $this->handler->getLastError(); + $result = $this->handler->$func($host, $port, $this->options['timeout']); + if($result === false) { + $this->handler->getLastError(); + } + + if (null != $this->options['password']) { + $this->handler->auth($this->options['password']); + } + + $this->handler->setOption(\Redis::OPT_SERIALIZER, $this->options['serialize']); + if(strlen($this->options['prefix'])) { + $this->handler->setOption(\Redis::OPT_PREFIX, $this->options['prefix']); + } + + APP_DEBUG && Log::record("[ CACHE ] INIT Redisd : {$host}:{$port} master->" . var_export($master, true), Log::ALERT); } catch (\RedisException $e) { //phpredis throws a RedisException object if it can't reach the Redis server. //That can happen in case of connectivity issues, if the Redis service is down, or if the redis host is overloaded. @@ -203,9 +211,8 @@ class Redisd { $this->master($master); - $value = null; try { - $value = $this->handler->get($this->options['prefix'] . $name); + $value = $this->handler->get($name); } catch (\RedisException $e) { unset(self::$redis_rw_handler[0]); @@ -215,13 +222,7 @@ class Redisd Log::record($e->getMessage(), Log::ERROR); } - $jsonData = null; - //如果是对象则进行反转 - if (!empty($value) && false !== strpos("[{", $value[0])) { - $jsonData = $value ? json_decode($value, true) : $value; - } - - return (null === $jsonData) ? $value : $jsonData; + return isset($value) ? $value : null; } /** @@ -240,21 +241,12 @@ class Redisd if (is_null($expire)) { $expire = $this->options['expire']; } - $name = $this->options['prefix'] . $name; - /** - * 兼容历史版本 - * Redis不支持存储对象,存入对象会转换成字符串 - * 但在这里,对所有数据做json_decode会有性能开销 - */ - $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; - - if (null === $value) { - return $this->handler->delete($this->options['prefix'] . $name); - } - - // $expire < 0 则等于ttl操作,列为todo吧 try { + if (null === $value) { + return $this->handler->delete($name); + } + if (is_int($expire) && $expire) { $result = $this->handler->setex($name, $expire, $value); } else { @@ -282,7 +274,7 @@ class Redisd public function rm($name) { $this->master(true); - return $this->handler->delete($this->options['prefix'] . $name); + return $this->handler->delete($name); } /** @@ -303,7 +295,7 @@ class Redisd * * @access public * @param bool $master 指定主从节点,可以从主节点获取结果 - * @return object + * @return \Redis */ public function handler($master = true) { From dbe744370a4df0345970c02d4a1f012686947b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Mon, 9 May 2016 19:55:33 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E5=8F=96=E6=B6=88hhvm=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/debugTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index 90c5cb93..8a9ac863 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -33,10 +33,6 @@ class debugTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - if (strstr(PHP_VERSION, 'hhvm')) { - $this->markTestSkipped("HHVM下跳过测试"); - } - $this->object = new Debug(); } @@ -164,6 +160,10 @@ class debugTest extends \PHPUnit_Framework_TestCase */ public function testDump() { + if (strstr(PHP_VERSION, 'hhvm')) { + return ; + } + $var = []; $var["key"] = "val"; $output = Debug::dump($var, false, $label = "label");