Skip to content

Commit 414fa21

Browse files
committed
Small fixes
1 parent e4e2943 commit 414fa21

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/Dashboards/Redis/RedisDashboard.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use Exception;
1616
use Redis;
17+
use RedisException;
1718
use RobiNN\Pca\Config;
1819
use RobiNN\Pca\Dashboards\DashboardException;
1920
use RobiNN\Pca\Dashboards\DashboardInterface;
@@ -130,7 +131,7 @@ public function ajax(): string {
130131
if (isset($_GET['delete'])) {
131132
$return = $this->deleteKey($redis);
132133
}
133-
} catch (DashboardException $e) {
134+
} catch (DashboardException|RedisException $e) {
134135
$return = $e->getMessage();
135136
}
136137
}
@@ -197,7 +198,7 @@ public function dashboard(): string {
197198
} else {
198199
$return = $this->mainDashboard($redis);
199200
}
200-
} catch (Exception $e) {
201+
} catch (DashboardException|RedisException $e) {
201202
return $e->getMessage();
202203
}
203204
}

src/Dashboards/Redis/RedisTrait.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace RobiNN\Pca\Dashboards\Redis;
1414

1515
use Redis;
16+
use RedisException;
1617
use RobiNN\Pca\Dashboards\DashboardException;
1718
use RobiNN\Pca\Helpers;
1819
use RobiNN\Pca\Http;
@@ -65,7 +66,7 @@ private function serverInfo(array $servers): array {
6566
'Memory used' => Helpers::formatBytes($server_info['used_memory']),
6667
'Keys' => Helpers::formatNumber($all_keys).' (all databases)',
6768
];
68-
} catch (DashboardException $e) {
69+
} catch (DashboardException|RedisException $e) {
6970
$data = [
7071
'error' => $e->getMessage(),
7172
];
@@ -80,6 +81,7 @@ private function serverInfo(array $servers): array {
8081
* @param Redis $redis
8182
*
8283
* @return string
84+
* @throws RedisException
8385
*/
8486
private function deleteAllKeys(Redis $redis): string {
8587
if ($redis->flushDB()) {
@@ -97,6 +99,7 @@ private function deleteAllKeys(Redis $redis): string {
9799
* @param Redis $redis
98100
*
99101
* @return string
102+
* @throws RedisException
100103
*/
101104
private function deleteKey(Redis $redis): string {
102105
$keys = explode(',', Http::get('delete'));
@@ -119,6 +122,7 @@ private function deleteKey(Redis $redis): string {
119122
* @param Redis $redis
120123
*
121124
* @return array<string, mixed>
125+
* @throws RedisException
122126
*/
123127
private function getInfo(Redis $redis): array {
124128
$options = ['SERVER', 'CLIENTS', 'MEMORY', 'PERSISTENCE', 'STATS', 'REPLICATION', 'CPU', 'CLASTER', 'KEYSPACE', 'COMANDSTATS'];
@@ -166,7 +170,7 @@ private function moreInfo(array $servers): string {
166170
'array' => $this->getInfo($redis),
167171
'bottom_content' => method_exists($redis, 'resetStat') && isset($reset_link) ? $reset_link : '',
168172
]);
169-
} catch (DashboardException $e) {
173+
} catch (DashboardException|RedisException $e) {
170174
return $e->getMessage();
171175
}
172176
}
@@ -177,6 +181,7 @@ private function moreInfo(array $servers): string {
177181
* @param Redis $redis
178182
*
179183
* @return array<int, string>
184+
* @throws RedisException
180185
*/
181186
private function getDatabases(Redis $redis): array {
182187
$databases = [];
@@ -207,6 +212,7 @@ private function getDatabases(Redis $redis): array {
207212
* @param Redis $redis
208213
*
209214
* @return array<int, array<string, string|int>>
215+
* @throws RedisException
210216
*/
211217
private function getAllKeys(Redis $redis): array {
212218
static $keys = [];
@@ -235,6 +241,7 @@ private function getAllKeys(Redis $redis): array {
235241
* @param Redis $redis
236242
*
237243
* @return string
244+
* @throws RedisException
238245
*/
239246
private function mainDashboard(Redis $redis): string {
240247
$keys = $this->getAllKeys($redis);
@@ -264,6 +271,7 @@ private function mainDashboard(Redis $redis): string {
264271
* @param Redis $redis
265272
*
266273
* @return string
274+
* @throws RedisException
267275
*/
268276
private function viewKey(Redis $redis): string {
269277
$key = Http::get('key');
@@ -342,6 +350,7 @@ private function viewKey(Redis $redis): string {
342350
* @param Redis $redis
343351
*
344352
* @return void
353+
* @throws RedisException
345354
*/
346355
private function import(Redis $redis): void {
347356
if ($_FILES['import']['type'] === 'application/octet-stream') {
@@ -366,6 +375,7 @@ private function import(Redis $redis): void {
366375
* @param Redis $redis
367376
*
368377
* @return string
378+
* @throws RedisException
369379
*/
370380
private function form(Redis $redis): string {
371381
$key = Http::get('key');

src/Dashboards/Redis/TypesTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace RobiNN\Pca\Dashboards\Redis;
1414

1515
use Redis;
16+
use RedisException;
1617
use RobiNN\Pca\Helpers;
1718
use RobiNN\Pca\Http;
1819

@@ -45,6 +46,7 @@ private function getType(int $type): string {
4546
* @param string $key
4647
*
4748
* @return array<mixed, mixed>
49+
* @throws RedisException
4850
*/
4951
private function getKeyValue(Redis $redis, string $type, string $key): array {
5052
$value = '';
@@ -99,6 +101,7 @@ private function getKeyValue(Redis $redis, string $type, string $key): array {
99101
* @param string $key
100102
*
101103
* @return array<mixed, mixed>|string
104+
* @throws RedisException
102105
*/
103106
private function getAllKeyValues(Redis $redis, string $type, string $key) {
104107
switch ($type) {
@@ -130,6 +133,7 @@ private function getAllKeyValues(Redis $redis, string $type, string $key) {
130133
* @param Redis $redis
131134
*
132135
* @return void
136+
* @throws RedisException
133137
*/
134138
private function saveKey(Redis $redis): void {
135139
if (isset($_POST['submit'])) {
@@ -211,6 +215,7 @@ private function saveKey(Redis $redis): void {
211215
* @param string $key
212216
*
213217
* @return void
218+
* @throws RedisException
214219
*/
215220
private function deleteSubKey(Redis $redis, string $type, string $key): void {
216221
switch ($type) {
@@ -242,6 +247,7 @@ private function deleteSubKey(Redis $redis, string $type, string $key): void {
242247
* @param string $key
243248
*
244249
* @return int|null
250+
* @throws RedisException
245251
*/
246252
private function getCountOfItemsInKey(Redis $redis, string $type, string $key): ?int {
247253
switch ($type) {

0 commit comments

Comments
 (0)