diff --git a/lib/Cake/Cache/Engine/RedisEngine.php b/lib/Cake/Cache/Engine/RedisEngine.php index 8dd98fb99..00c84261d 100644 --- a/lib/Cake/Cache/Engine/RedisEngine.php +++ b/lib/Cake/Cache/Engine/RedisEngine.php @@ -133,11 +133,11 @@ class RedisEngine extends CacheEngine { */ public function read($key) { $value = $this->_Redis->get($key); - if (ctype_digit($value)) { - $value = (int)$value; + if (preg_match('/^[-]?\d+$/', $value)) { + return (int)$value; } if ($value !== false && is_string($value)) { - $value = unserialize($value); + return unserialize($value); } return $value; } diff --git a/lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php index aec71a3ba..23c5fa8ec 100644 --- a/lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php @@ -144,6 +144,22 @@ class RedisEngineTest extends CakeTestCase { Cache::drop('redisdb1'); } +/** + * test write numbers method + * + * @return void + */ + public function testWriteNumbers() { + $result = Cache::write('test-counter', 1, 'redis'); + $this->assertSame(1, Cache::read('test-counter', 'redis')); + + $result = Cache::write('test-counter', 0, 'redis'); + $this->assertSame(0, Cache::read('test-counter', 'redis')); + + $result = Cache::write('test-counter', -1, 'redis'); + $this->assertSame(-1, Cache::read('test-counter', 'redis')); + } + /** * testReadAndWriteCache method *