Skip to content

Commit 2c2ef78

Browse files
committed
fix(Cache): use __ci_value field in PredisHandler::increment() and decrement()
1 parent 59e5eea commit 2c2ef78

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎system/Cache/Handlers/PredisHandler.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ public function increment(string $key, int $offset = 1): int
155155
{
156156
$key = static::validateKey($key);
157157

158-
return $this->redis->hincrby($key, 'data', $offset);
158+
return $this->redis->hincrby($key, '__ci_value', $offset);
159159
}
160160

161161
public function decrement(string $key, int $offset = 1): int
162162
{
163163
$key = static::validateKey($key);
164164

165-
return $this->redis->hincrby($key, 'data', -$offset);
165+
return $this->redis->hincrby($key, '__ci_value', -$offset);
166166
}
167167

168168
public function clean(): bool

‎tests/system/Cache/Handlers/PredisHandlerTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,23 @@ public function testDeleteMatchingNothing(): void
162162
$this->assertSame(0, $this->handler->deleteMatching('user_1_info*'));
163163
}
164164

165+
public function testIncrementAndDecrement(): void
166+
{
167+
$this->handler->save('counter', 100);
168+
169+
foreach (range(1, 10) as $step) {
170+
$this->handler->increment('counter', $step);
171+
}
172+
173+
$this->assertSame(155, $this->handler->get('counter'));
174+
175+
$this->handler->decrement('counter', 20);
176+
$this->assertSame(135, $this->handler->get('counter'));
177+
178+
$this->handler->increment('counter', 5);
179+
$this->assertSame(140, $this->handler->get('counter'));
180+
}
181+
165182
public function testClean(): void
166183
{
167184
$this->handler->save(self::$key1, 1);

0 commit comments

Comments
 (0)