Skip to content

Commit 5ba9266

Browse files
committed
Fix SLOWLOG when disabled
1 parent 53a775a commit 5ba9266

File tree

6 files changed

+45
-40
lines changed

6 files changed

+45
-40
lines changed

src/Dashboards/Redis/Compatibility/Cluster/PredisCluster.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,12 @@ public function resetSlowlog(): bool {
329329
return true;
330330
}
331331

332-
public function isCommandSupported(string $command): bool {
333-
try {
334-
$commands = $this->nodes[0]->executeRaw(['COMMAND']);
335-
$command_names = array_column($commands, 0);
336-
$is_supported = in_array(strtolower($command), $command_names, true);
337-
} catch (Exception) {
338-
$is_supported = false;
339-
}
332+
/**
333+
* @return array<int, string>
334+
*/
335+
public function getCommands(): array {
336+
$commands = $this->nodes[0]->executeRaw(['COMMAND']);
340337

341-
return $is_supported;
338+
return array_column($commands, 0);
342339
}
343340
}

src/Dashboards/Redis/Compatibility/Cluster/RedisCluster.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,12 @@ public function resetSlowlog(): bool {
334334
return true;
335335
}
336336

337-
public function isCommandSupported(string $command): bool {
338-
try {
339-
$commands = $this->rawcommand($this->nodes[0], 'COMMAND');
340-
$command_names = array_column($commands, 0);
341-
$is_supported = in_array(strtolower($command), $command_names, true);
342-
} catch (RedisClusterException) {
343-
$is_supported = false;
344-
}
337+
/**
338+
* @return array<int, string>
339+
*/
340+
public function getCommands(): array {
341+
$commands = $this->rawcommand($this->nodes[0], 'COMMAND');
345342

346-
return $is_supported;
343+
return array_column($commands, 0);
347344
}
348345
}

src/Dashboards/Redis/Compatibility/Predis.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
namespace RobiNN\Pca\Dashboards\Redis\Compatibility;
1010

11-
use Exception;
1211
use Predis\Client;
1312
use Predis\Collection\Iterator\Keyspace;
1413

@@ -199,15 +198,12 @@ public function resetSlowlog(): bool {
199198
return $this->slowlog('RESET') === 'OK';
200199
}
201200

202-
public function isCommandSupported(string $command): bool {
203-
try {
204-
$commands = $this->rawcommand('COMMAND');
205-
$command_names = array_column($commands, 0);
206-
$is_supported = in_array(strtolower($command), $command_names, true);
207-
} catch (Exception) {
208-
$is_supported = false;
209-
}
201+
/**
202+
* @return array<int, string>
203+
*/
204+
public function getCommands(): array {
205+
$commands = $this->rawcommand('COMMAND');
210206

211-
return $is_supported;
207+
return array_column($commands, 0);
212208
}
213209
}

src/Dashboards/Redis/Compatibility/Redis.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,12 @@ public function resetSlowlog(): bool {
214214
return $this->slowlog('RESET');
215215
}
216216

217-
public function isCommandSupported(string $command): bool {
218-
try {
219-
$commands = $this->rawcommand('COMMAND');
220-
$command_names = array_column($commands, 0);
221-
$is_supported = in_array(strtolower($command), $command_names, true);
222-
} catch (RedisException) {
223-
$is_supported = false;
224-
}
217+
/**
218+
* @return array<int, string>
219+
*/
220+
public function getCommands(): array {
221+
$commands = $this->rawcommand('COMMAND');
225222

226-
return $is_supported;
223+
return array_column($commands, 0);
227224
}
228225
}

src/Dashboards/Redis/Compatibility/RedisCompatibilityInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function getSlowlog(int $count): ?array;
9393
public function resetSlowlog(): bool;
9494

9595
/**
96-
* Check if a command is supported.
96+
* Get a list of supported commands.
97+
*
98+
* @return array<int, string>
9799
*/
98-
public function isCommandSupported(string $command): bool;
100+
public function getCommands(): array;
99101
}

src/Dashboards/Redis/RedisTrait.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function getAllKeys(): array {
360360
$filter = Http::get('s', '*');
361361
$this->template->addGlobal('search_value', $filter);
362362

363-
if (isset($this->servers[$this->current_server]['scansize']) || !$this->redis->isCommandSupported('KEYS')) {
363+
if (isset($this->servers[$this->current_server]['scansize']) || !$this->isCommandSupported('KEYS')) {
364364
$scansize = (int) ($this->servers[$this->current_server]['scansize'] ?? 1000);
365365
$keys_array = $this->redis->scanKeys($filter, $scansize);
366366
} else {
@@ -376,6 +376,17 @@ public function getAllKeys(): array {
376376
return $this->keysTableView($keys);
377377
}
378378

379+
public function isCommandSupported(string $command): bool {
380+
try {
381+
$commands = $this->redis->getCommands();
382+
$is_supported = in_array(strtolower($command), $commands, true);
383+
} catch (Exception) {
384+
$is_supported = false;
385+
}
386+
387+
return $is_supported;
388+
}
389+
379390
/**
380391
* @param array<int|string, mixed> $keys
381392
*
@@ -513,6 +524,11 @@ private function dbSelect(): string {
513524
* @throws Exception
514525
*/
515526
private function slowlog(): string {
527+
if (!$this->isCommandSupported('SLOWLOG')) {
528+
return $this->template->render('components/tabs', ['links' => ['keys' => 'Keys', 'slowlog' => 'Slow Log',],]).
529+
'Slowlog is disabled on your server.';
530+
}
531+
516532
if (isset($_GET['resetlog'])) {
517533
$this->redis->resetSlowlog();
518534
Http::redirect(['tab']);

0 commit comments

Comments
 (0)