From 2c2ef788303e95e88dc62d391af07a98ca0bf4f3 Mon Sep 17 00:00:00 2001 From: banghamid <62824084+banghamid@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:14:19 +0700 Subject: [PATCH 1/2] fix(Cache): use __ci_value field in PredisHandler::increment() and decrement() --- system/Cache/Handlers/PredisHandler.php | 4 ++-- .../system/Cache/Handlers/PredisHandlerTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) 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..bf9be5ca4726 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->handler->decrement('counter', 20); + $this->assertSame(135, $this->handler->get('counter')); + + $this->handler->increment('counter', 5); + $this->assertSame(140, $this->handler->get('counter')); + } + public function testClean(): void { $this->handler->save(self::$key1, 1); From 9f87b87dba8d5babf0a0dfb7013cdb3e2598722a Mon Sep 17 00:00:00 2001 From: banghamid <62824084+banghamid@users.noreply.github.com> Date: Thu, 12 Nov 2026 01:22:37 +0700 Subject: [PATCH 2/2] test(Cache): assert increment and decrement return values --- tests/system/Cache/Handlers/PredisHandlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system/Cache/Handlers/PredisHandlerTest.php b/tests/system/Cache/Handlers/PredisHandlerTest.php index bf9be5ca4726..9f5b63b13309 100644 --- a/tests/system/Cache/Handlers/PredisHandlerTest.php +++ b/tests/system/Cache/Handlers/PredisHandlerTest.php @@ -172,10 +172,10 @@ public function testIncrementAndDecrement(): void $this->assertSame(155, $this->handler->get('counter')); - $this->handler->decrement('counter', 20); + $this->assertSame(135, $this->handler->decrement('counter', 20)); $this->assertSame(135, $this->handler->get('counter')); - $this->handler->increment('counter', 5); + $this->assertSame(140, $this->handler->increment('counter', 5)); $this->assertSame(140, $this->handler->get('counter')); }