Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/107' into develop, Forward port #107
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Sep 19, 2016
2 parents c14dfd6 + 722af9c commit cbd5ae0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#107](https://github.com/zendframework/zend-cache/issues/107)
fixed redis server version test in Redis::internalGetMetadata()
- [#111](https://github.com/zendframework/zend-cache/pull/111)
Fixed typo in storage adapter doc
- [#102](https://github.com/zendframework/zend-cache/pull/102)
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/Adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ protected function internalGetMetadata(& $normalizedKey)
$metadata = [];

try {
$redisVersion = $this->resourceManager->getMajorVersion($this->resourceId);
$redisVersion = $this->resourceManager->getVersion($this->resourceId);

// redis >= 2.8
// The command 'pttl' returns -2 if the item does not exist
Expand All @@ -565,8 +565,8 @@ protected function internalGetMetadata(& $normalizedKey)
}
$metadata['ttl'] = ($pttl == -1) ? null : $pttl / 1000;

// redis >= 2.6
// The command 'pttl' returns -1 if the item does not exist or the item as no associated expire
// redis >= 2.6, < 2.8
// The command 'pttl' returns -1 if the item does not exist or the item has no associated expire
} elseif (version_compare($redisVersion, '2.6', '>=')) {
$pttl = $redis->pttl($this->namespacePrefix . $normalizedKey);
if ($pttl <= -1) {
Expand All @@ -578,7 +578,7 @@ protected function internalGetMetadata(& $normalizedKey)
$metadata['ttl'] = $pttl / 1000;
}

// redis >= 2
// redis >= 2, < 2.6
// The command 'pttl' is not supported but 'ttl'
// The command 'ttl' returns 0 if the item does not exist same as if the item is going to be expired
// NOTE: In case of ttl=0 we return false because the item is going to be expired in a very near future
Expand Down
23 changes: 19 additions & 4 deletions src/Storage/Adapter/RedisResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,31 @@ public function hasResource($id)
/**
* Get redis server version
*
* @param string $id
* @param string $resourceId
* @return string
* @throws Exception\RuntimeException
*/
public function getVersion($resourceId)
{
// check resource id and initialize the resource
$this->getResource($resourceId);

return $this->resources[$resourceId]['version'];
}

/**
* Get redis major server version
*
* @param string $resourceId
* @return int
* @throws Exception\RuntimeException
*/
public function getMajorVersion($id)
public function getMajorVersion($resourceId)
{
// check resource id and initialize the resource
$this->getResource($id);
$this->getResource($resourceId);

return (int) $this->resources[$id]['version'];
return (int) $this->resources[$resourceId]['version'];
}

/**
Expand Down
25 changes: 22 additions & 3 deletions test/Storage/Adapter/RedisResourceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,28 @@ public function testNotValidPersistentIdOptionName()
$this->assertInstanceOf('Redis', $this->resourceManager->getResource($resourceId));
}

/**
* Test with 'persistend_id' instead of 'persistent_id'
*/
public function testGetVersion()
{
if (getenv('TESTS_ZEND_CACHE_REDIS_ENABLED') != 'true') {
$this->markTestSkipped('Enable TESTS_ZEND_CACHE_REDIS_ENABLED to run this test');
}

if (!extension_loaded('redis')) {
$this->markTestSkipped("Redis extension is not loaded");
}

$resourceId = __FUNCTION__;
$resource = [
'server' => [
'host' => getenv('TESTS_ZEND_CACHE_REDIS_HOST') ?: 'localhost',
'port' => getenv('TESTS_ZEND_CACHE_REDIS_PORT') ?: 6379,
],
];
$this->resourceManager->setResource($resourceId, $resource);

$this->assertRegExp('/^\d+\.\d+\.\d+/', $this->resourceManager->getVersion($resourceId));
}

public function testGetMajorVersion()
{
if (getenv('TESTS_ZEND_CACHE_REDIS_ENABLED') != 'true') {
Expand Down

0 comments on commit cbd5ae0

Please sign in to comment.