Skip to content

Commit

Permalink
Memcached fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNN1 committed Feb 16, 2025
1 parent f04ff67 commit 8553df2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ services:
- PHP >= 8.2 (Use [v1 branch](https://github.com/RobiNN1/phpCacheAdmin/tree/v1.x) if you need support for >=7.4)
- Redis server >= 3.0.0
- Memcached server >= 1.4.31. If you do not see the keys, you need to enable `lru_crawler`. SASL is not supported because there is no way to get the keys.
- Memcached server >= 1.4.31 (ideally >= 1.5.19 to see more data). If you do not see the keys, you need to enable `lru_crawler`. SASL is not supported because there is no way to get the keys.

> It is not necessary to have all dashboards enabled.

Expand Down
6 changes: 3 additions & 3 deletions src/Dashboards/Memcached/MemcachedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function viewKey(): string {
}

$info = $this->memcached->getKeyMeta($key);
$ttl = $info['exp'];
$ttl = $info['exp'] ?? null;
$ttl = $ttl === 0 ? -1 : $ttl;

if (isset($_GET['export'])) {
Expand All @@ -135,8 +135,8 @@ private function viewKey(): string {
return $this->template->render('partials/view_key', [
'key' => $key,
'value' => $formatted_value,
'ttl' => Format::seconds($ttl),
'size' => Format::bytes($info['size']),
'ttl' => $ttl ? Format::seconds($ttl) : null,
'size' => isset($info['size']) ? Format::bytes($info['size']) : null,
'encode_fn' => $encode_fn,
'formatted' => $is_formatted,
'edit_url' => Http::queryString(['ttl'], ['form' => 'edit', 'key' => $key]),
Expand Down
9 changes: 9 additions & 0 deletions src/Dashboards/Memcached/PHPMem.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,21 @@ public function getKey(string $key): string|false {
/**
* Get key meta-data.
*
* This command requires Memcached server >= 1.5.19
*
* @link https://github.com/memcached/memcached/wiki/ReleaseNotes1519
*
* @return array<string, string|int>
*
* @throws MemcachedException
*/
public function getKeyMeta(string $key): array {
$raw = $this->runCommand('me '.$key);

if ($raw === 'ERROR') {
return [];
}

$raw = preg_replace('/^ME\s+\S+\s+/', '', $raw); // Remove `ME keyname`

return $this->parseLine($raw);
Expand Down

0 comments on commit 8553df2

Please sign in to comment.