diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index df179e7455e6..b84c0115b1f8 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -200,7 +200,7 @@ public function increment(string $key, int $offset = 1) { $key = static::validateKey($key, $this->prefix); - return $this->redis->hIncrBy($key, 'data', $offset); + return $this->redis->hIncrBy($key, '__ci_value', $offset); } /** @@ -208,9 +208,7 @@ public function increment(string $key, int $offset = 1) */ public function decrement(string $key, int $offset = 1) { - $key = static::validateKey($key, $this->prefix); - - return $this->redis->hIncrBy($key, 'data', -$offset); + return $this->increment($key, -$offset); } /** diff --git a/tests/system/Cache/Handlers/RedisHandlerTest.php b/tests/system/Cache/Handlers/RedisHandlerTest.php index a10d92171ec8..2c79be076eca 100644 --- a/tests/system/Cache/Handlers/RedisHandlerTest.php +++ b/tests/system/Cache/Handlers/RedisHandlerTest.php @@ -166,14 +166,22 @@ public function testDeleteMatchingSuffix() $this->assertSame('keys=90', $dbInfo[0]); } - // FIXME: I don't like all Hash logic very much. It's wasting memory. - // public function testIncrement() - // { - // } - - // public function testDecrement() - // { - // } + public function testIncrementAndDecrement() + { + $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() {