mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #8365 from cakephp/issue-8364
2.x - Handle negative numbers in Redis correctly.
This commit is contained in:
commit
da15674a2c
2 changed files with 19 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue