From c1e9d3b1984859683c1962e617fa75fdb8420b01 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Wed, 26 Oct 2016 22:58:10 +0200 Subject: [PATCH 1/3] fixed redis tests in case running with different server than 127.0.0.1:6379 --- src/Storage/Adapter/RedisResourceManager.php | 2 +- test/Storage/Adapter/RedisTest.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Storage/Adapter/RedisResourceManager.php b/src/Storage/Adapter/RedisResourceManager.php index fa2ddd616..c08180604 100644 --- a/src/Storage/Adapter/RedisResourceManager.php +++ b/src/Storage/Adapter/RedisResourceManager.php @@ -118,7 +118,7 @@ public function getPassword($id) * Gets a redis resource * * @param string $id - * @return RedisResourceManager + * @return RedisResource * @throws Exception\RuntimeException */ public function getResource($id) diff --git a/test/Storage/Adapter/RedisTest.php b/test/Storage/Adapter/RedisTest.php index 7b03ff8bb..5a8f02a7e 100644 --- a/test/Storage/Adapter/RedisTest.php +++ b/test/Storage/Adapter/RedisTest.php @@ -119,14 +119,12 @@ public function testRedisSetBoolean() public function testGetCapabilitiesTtl() { - $host = getenv('TESTS_ZEND_CACHE_REDIS_HOST') ? : '127.0.0.1'; - $port = getenv('TESTS_ZEND_CACHE_REDIS_PORT') ? : 6379; - $redisResource = new RedisResource(); - $redisResource->connect($host, $port); - $info = $redisResource->info(); - $majorVersion = (int) $info['redis_version']; + $resourceManager = $this->_options->getResourceManager(); + $resourceId = $this->_options->getResourceId(); + $redis = $resourceManager->getResource($resourceId); + $majorVersion = (int) $redis->info()['redis_version']; - $this->assertEquals($majorVersion, $this->_options->getResourceManager()->getMajorVersion($this->_options->getResourceId())); + $this->assertEquals($majorVersion, $resourceManager->getMajorVersion($resourceId)); $capabilities = $this->_storage->getCapabilities(); if ($majorVersion < 2) { @@ -145,6 +143,7 @@ public function testSocketConnection() $normalized = $this->_options->getResourceManager()->getServer($this->_options->getResourceId()); $this->assertEquals($socket, $normalized['host'], 'Host should equal to socket {$socket}'); + // Don't try to flush on shutdown $this->_storage = null; } @@ -271,6 +270,9 @@ public function testGetSetServer() ]; $this->_options->setServer($server); $this->assertEquals($server, $this->_options->getServer(), 'Server was not set correctly through RedisOptions'); + + // Don't try to flush on shutdown + $this->_storage = null; } public function testOptionsGetSetDatabase() From 5bc51131864c624da2777bdf8701ef3ee61987ab Mon Sep 17 00:00:00 2001 From: Moln Date: Thu, 27 Oct 2016 12:03:14 +0800 Subject: [PATCH 2/3] 1. We don't need call info method every time we want redis resource. +1 --- src/Storage/Adapter/RedisResourceManager.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Storage/Adapter/RedisResourceManager.php b/src/Storage/Adapter/RedisResourceManager.php index fa2ddd616..038dfc24e 100644 --- a/src/Storage/Adapter/RedisResourceManager.php +++ b/src/Storage/Adapter/RedisResourceManager.php @@ -118,7 +118,7 @@ public function getPassword($id) * Gets a redis resource * * @param string $id - * @return RedisResourceManager + * @return RedisResource * @throws Exception\RuntimeException */ public function getResource($id) @@ -133,8 +133,12 @@ public function getResource($id) if (!$resource['initialized']) { $this->connect($resource); } - $info = $resource['resource']->info(); - $resource['version'] = $info['redis_version']; + + if (!$resource['version']) { + $info = $resource['resource']->info(); + $resource['version'] = $info['redis_version']; + } + return $resource['resource']; } From e64e5198de8c99454ae6135b17912a97e17edb79 Mon Sep 17 00:00:00 2001 From: Marc Bennewitz Date: Fri, 4 Nov 2016 22:32:30 +0100 Subject: [PATCH 3/3] Added #118 to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1515115d..8927f4d7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed +- [#118](https://github.com/zendframework/zend-cache/pull/118) + fixed redis tests in case running with different server - [#119](https://github.com/zendframework/zend-cache/pull/119) Redis: Don't call method Redis::info() every time - [#113](https://github.com/zendframework/zend-cache/pull/113)