Skip to content

Commit ecdd93f

Browse files
authored
fix: use __ci_value field in PredisHandler::increment() and decrement() (#10758)
1 parent 23fee28 commit ecdd93f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎docs/changelogs/v4.7.7.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Release Date: Unreleased
1818

1919
## Bugs Fixed
2020

21+
- **Cache:** Fixed a bug where `PredisHandler::increment()` and `PredisHandler::decrement()` updated the unused `'data'` hash field instead of `'__ci_value'`, causing `get()` to return stale values for existing counters.
2122
- **CORS:** Fixed a bug where `Cors::hasResponseHeaders()` matched header substrings via `str_contains()`, causing false positives when existing exposed headers shared a prefix with configured exposed headers.
2223
- **Database:** Fixed a bug where `Postgre`, `OCI8`, and `SQLSRV` `Forge::_dropKeyAsConstraint()` interpolated table, constraint, and schema names without escaping.
2324
- **Database:** Fixed a bug where `Postgre\Connection::insertID()` interpolated table, column, and sequence names without escaping.

‎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->assertSame(135, $this->handler->decrement('counter', 20));
176+
$this->assertSame(135, $this->handler->get('counter'));
177+
178+
$this->assertSame(140, $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)