Skip to content

Commit 97eccdb

Browse files
committed
fix: support not having a Redis connection in insights
1 parent c1635fe commit 97eccdb

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

packages/kv-store/src/Redis/PhpRedisClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public function __construct(
2222

2323
public function connect(): void
2424
{
25+
if ($this->client->isConnected()) {
26+
return;
27+
}
28+
2529
if ($this->config->persistent) {
2630
$this->client->pconnect(
2731
host: $this->config->unixSocketPath ?? $this->config->host ?? '127.0.0.1',

packages/kv-store/src/Redis/PredisClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function __construct(
1919

2020
public function connect(): void
2121
{
22+
if ($this->client->isConnected()) {
23+
return;
24+
}
25+
2226
$this->client->connect();
2327
}
2428

packages/kv-store/src/Redis/RedisInsightsProvider.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ public function __construct(
1818
public function getInsights(): array
1919
{
2020
$client = $this->redis->getClient();
21-
$version = Regex\get_match($this->redis->command('info', 'server'), '/redis_version:(?<version>[0-9.]+)/', match: 'version');
2221

23-
return [
24-
'Engine' => match (get_class($client)) {
25-
\Redis::class => 'Redis extension',
26-
Predis\Client::class => 'Predis',
27-
default => new Insight('None', Insight::WARNING),
28-
},
29-
'Version' => $version ?: new Insight('Unknown', Insight::WARNING),
30-
];
22+
try {
23+
$version = Regex\get_match($this->redis->command('info', 'server'), '/redis_version:(?<version>[0-9.]+)/', match: 'version');
24+
25+
return [
26+
'Engine' => match (get_class($client)) {
27+
\Redis::class => 'Redis extension',
28+
Predis\Client::class => 'Predis',
29+
default => new Insight('None', Insight::WARNING),
30+
},
31+
'Version' => $version ?: new Insight('Unknown', Insight::WARNING),
32+
];
33+
} catch (\Throwable) {
34+
return [
35+
'Engine' => new Insight('Disconnected', Insight::ERROR),
36+
];
37+
}
3138
}
3239
}

0 commit comments

Comments
 (0)