From 0061f52a313b246202d5c8a2ae2a59886939e373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 08:48:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20redis=20connect=20time?= =?UTF-8?q?,=20redis=E6=89=A9=E5=B1=95=E5=B7=B2=E5=85=BC=E5=AE=B9time?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redis.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index e31d38f7..176949e8 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -15,7 +15,9 @@ use think\Cache; use think\Exception; /** - * Redis缓存驱动 + * Redis缓存驱动,适合单机部署、有前端代理实现高可用的场景,性能最好 + * 有需要在业务层实现读写分离、或者使用RedisCluster的需求,请使用Redisd驱动 + * * 要求安装phpredis扩展:https://github.com/nicolasff/phpredis * @author 尘缘 <130775@qq.com> */ @@ -26,7 +28,7 @@ class Redis 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', - 'timeout' => false, + 'timeout' => 0, 'expire' => false, 'persistent' => false, 'length' => 0, @@ -48,9 +50,8 @@ class Redis } $func = $this->options['persistent'] ? 'pconnect' : 'connect'; $this->handler = new \Redis; - false === $this->options['timeout'] ? - $this->handler->$func($this->options['host'], $this->options['port']) : $this->handler->$func($this->options['host'], $this->options['port'], $this->options['timeout']); + if ('' != $this->options['password']) { $this->handler->auth($this->options['password']); } From b5d7338bcead063e2365b429900ec233f90b3a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 08:50:37 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20redis=20set=EF=BC=8Cre?= =?UTF-8?q?dis=E4=B8=8D=E8=83=BD=E8=AE=BE=E7=BD=AE=E4=B8=80=E4=B8=AA=20exp?= =?UTF-8?q?ire=20=E4=B8=BA=200=20=E7=9A=84key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redis.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index 176949e8..23455a1d 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -29,7 +29,7 @@ class Redis 'port' => 6379, 'password' => '', 'timeout' => 0, - 'expire' => false, + 'expire' => 0, 'persistent' => false, 'length' => 0, 'prefix' => '', @@ -87,7 +87,7 @@ class Redis $name = $this->options['prefix'] . $name; //对数组/对象数据进行缓存处理,保证数据完整性 byron sampson $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; - if (is_int($expire)) { + if (is_int($expire) && $expire) { $result = $this->handler->setex($name, $expire, $value); } else { $result = $this->handler->set($name, $value); From 2ace73254f8d32e97e76ae9f7b95015e2cb16b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 08:54:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4db=20cache=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/dbTest.php | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 tests/thinkphp/library/think/cache/driver/dbTest.php diff --git a/tests/thinkphp/library/think/cache/driver/dbTest.php b/tests/thinkphp/library/think/cache/driver/dbTest.php deleted file mode 100644 index 9c896d4f..00000000 --- a/tests/thinkphp/library/think/cache/driver/dbTest.php +++ /dev/null @@ -1,43 +0,0 @@ - -// +---------------------------------------------------------------------- - -/** - * 数据库缓存驱动测试 - * @author mahuan - */ - -namespace tests\thinkphp\library\think\cache\driver; - -class dbTest extends cacheTestCase -{ - private $_cacheInstance = null; - - /** - * 基境缓存类型 - */ - protected function setUp() - { - //数据库缓存测试因为缺少数据库单元测试所以暂时跳过 - $this->markTestSkipped("暂时跳过测试。"); - \think\Cache::connect(array('type' => 'db', 'expire' => 2)); - } - - /** - * @return DbCache - */ - protected function getCacheInstance() - { - if (null === $this->_cacheInstance) { - $this->_cacheInstance = new \think\cache\driver\Db(); - } - return $this->_cacheInstance; - } -} From f5a74eb60e3de32bf8ae6ed62a626d9664332915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=98=E7=BC=98?= Date: Sun, 8 May 2016 09:01:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20key=20expire=20=3D=200?= =?UTF-8?q?=20=E7=9A=84=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 --- tests/thinkphp/library/think/cache/driver/cacheTestCase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/thinkphp/library/think/cache/driver/cacheTestCase.php b/tests/thinkphp/library/think/cache/driver/cacheTestCase.php index ff123c13..c7bd407c 100644 --- a/tests/thinkphp/library/think/cache/driver/cacheTestCase.php +++ b/tests/thinkphp/library/think/cache/driver/cacheTestCase.php @@ -75,6 +75,9 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase $array = $cache->get('array_test'); $this->assertArrayHasKey('array_test', $array); $this->assertEquals('array_test', $array['array_test']); + + $result = $cache->set('no_expire', 1, 0); + $this->assertTrue($result); } /**