Skip to content

Commit

Permalink
Merge pull request zendframework#4830. Fix zendframework#4804 in master
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Jul 15, 2013
2 parents 4adfd93 + 5a5a6f1 commit 257488d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Cache/Storage/Adapter/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function internalSetItem(& $normalizedKey, & $value)

try {
if ($ttl) {
if ($this->resourceManager->getMayorVersion($this->resourceId) < 2) {
if ($this->resourceManager->getMajorVersion($this->resourceId) < 2) {
throw new Exception\UnsupportedMethodCallException("To use ttl you need version >= 2.0.0");
}
$success = $redis->setex($this->namespacePrefix . $normalizedKey, $ttl, $value);
Expand Down Expand Up @@ -260,7 +260,7 @@ protected function internalSetItems(array & $normalizedKeyValuePairs)
try {
if ($ttl > 0) {
//check if ttl is supported
if ($this->resourceManager->getMayorVersion($this->resourceId) < 2) {
if ($this->resourceManager->getMajorVersion($this->resourceId) < 2) {
throw new Exception\UnsupportedMethodCallException("To use ttl you need version >= 2.0.0");
}
//mSet does not allow ttl, so use transaction
Expand Down Expand Up @@ -402,7 +402,7 @@ protected function internalGetCapabilities()
{
if ($this->capabilities === null) {
$this->capabilityMarker = new stdClass();
$minTtl = $this->resourceManager->getMayorVersion($this->resourceId) < 2 ? 0 : 1;
$minTtl = $this->resourceManager->getMajorVersion($this->resourceId) < 2 ? 0 : 1;
//without serialization redis supports only strings for simple
//get/set methods
$this->capabilities = new Capabilities(
Expand Down
14 changes: 14 additions & 0 deletions library/Zend/Cache/Storage/Adapter/RedisResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,25 @@ public function getDatabase($id)
/**
* Get redis server version
*
* @deprecated 2.2.2 Use getMajorVersion instead
*
* @param string $id
* @return int
* @throws Exception\RuntimeException
*/
public function getMayorVersion($id)
{
return $this->getMajorVersion($id);
}

/**
* Get redis server version
*
* @param string $id
* @return int
* @throws Exception\RuntimeException
*/
public function getMajorVersion($id)
{
if (!$this->hasResource($id)) {
throw new Exception\RuntimeException("No resource with id '{$id}'");
Expand Down
6 changes: 3 additions & 3 deletions tests/ZendTest/Cache/Storage/Adapter/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public function testGetCapabilitiesTtl()
$redisResource = new RedisResource();
$redisResource->connect($host, $port);
$info = $redisResource->info();
$mayorVersion = (int)$info['redis_version'];
$majorVersion = (int)$info['redis_version'];

$this->assertEquals($mayorVersion, $this->_options->getResourceManager()->getMayorVersion($this->_options->getResourceId()));
$this->assertEquals($majorVersion, $this->_options->getResourceManager()->getMajorVersion($this->_options->getResourceId()));

$capabilities = $this->_storage->getCapabilities();
if ($mayorVersion < 2) {
if ($majorVersion < 2) {
$this->assertEquals(0, $capabilities->getMinTtl(), 'Redis version < 2.0.0 does not support key expiration');
} else {
$this->assertEquals(1, $capabilities->getMinTtl(), 'Redis version > 2.0.0 supports key expiration');
Expand Down

0 comments on commit 257488d

Please sign in to comment.