diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 79e7ae98f916..e8c4759ed9eb 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -155,14 +155,14 @@ public function increment(string $key, int $offset = 1): int { $key = static::validateKey($key); - return $this->redis->hincrby($key, 'data', $offset); + return $this->redis->hincrby($key, '__ci_value', $offset); } public function decrement(string $key, int $offset = 1): int { $key = static::validateKey($key); - return $this->redis->hincrby($key, 'data', -$offset); + return $this->redis->hincrby($key, '__ci_value', -$offset); } public function clean(): bool diff --git a/tests/system/Cache/Handlers/PredisHandlerTest.php b/tests/system/Cache/Handlers/PredisHandlerTest.php index 91949f53238f..9f5b63b13309 100644 --- a/tests/system/Cache/Handlers/PredisHandlerTest.php +++ b/tests/system/Cache/Handlers/PredisHandlerTest.php @@ -162,6 +162,23 @@ public function testDeleteMatchingNothing(): void $this->assertSame(0, $this->handler->deleteMatching('user_1_info*')); } + public function testIncrementAndDecrement(): void + { + $this->handler->save('counter', 100); + + foreach (range(1, 10) as $step) { + $this->handler->increment('counter', $step); + } + + $this->assertSame(155, $this->handler->get('counter')); + + $this->assertSame(135, $this->handler->decrement('counter', 20)); + $this->assertSame(135, $this->handler->get('counter')); + + $this->assertSame(140, $this->handler->increment('counter', 5)); + $this->assertSame(140, $this->handler->get('counter')); + } + public function testClean(): void { $this->handler->save(self::$key1, 1);