Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions system/Cache/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ public function decrement(string $key, int $offset = 1): false|int

$key = static::validateKey($key, $this->prefix);

// FIXME: third parameter isn't other handler actions.

return $this->memcached->decrement($key, $offset, $offset, 60);
// Memcached counters are unsigned, so a missing key can't be
// initialized to a negative value like the other handlers do.
// Fall back to Memcached::decrement()'s own default of 0 instead
// of $offset, so a new key no longer starts positive.
return $this->memcached->decrement($key, $offset, 0, 60);
Comment thread
michalsn marked this conversation as resolved.
Outdated
}

public function clean(): bool
Expand Down
4 changes: 3 additions & 1 deletion tests/system/Cache/Handlers/MemcachedHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public function testDecrement(): void

$this->assertSame(9, $memcachedHandler->decrement(self::$key1, 1));
$this->assertFalse($memcachedHandler->decrement(self::$key2, 1));
$this->assertSame(1, $memcachedHandler->decrement(self::$key3, 1));
// A key that doesn't exist yet starts at 0, not at the offset
// (Memcached counters are unsigned, so it can't start negative).
$this->assertSame(0, $memcachedHandler->decrement(self::$key3, 1));
Comment thread
michalsn marked this conversation as resolved.
Outdated
}

public function testClean(): void
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Bugs Fixed
- **Helpers:** Fixed a bug where ``get_dir_file_info()`` returned incomplete entries for subdirectories and missing files instead of omitting them.
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
- **Cache:** Fixed a bug where ``MemcachedHandler::decrement()`` on a non-existent key returned a positive value instead of ``0``, the opposite sign of what ``FileHandler``, ``RedisHandler``, and ``PredisHandler`` return.
Comment thread
michalsn marked this conversation as resolved.
Outdated

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down