Skip to content

Commit 37d0eea

Browse files
committed
fix: fix prefix for PHPRedis
Signed-off-by: Mateusz Cholewka <mateusz@cholewka.com.pl>
1 parent 6ba18b8 commit 37d0eea

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/Prometheus/Storage/AbstractRedis.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected function collectHistograms(): array
292292
sort($keys);
293293
$histograms = [];
294294
foreach ($keys as $key) {
295-
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->prefix('')));
295+
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->getOption(RedisClient::OPT_PREFIX) ?? ''));
296296
if (! isset($raw['__meta'])) {
297297
continue;
298298
}
@@ -373,7 +373,7 @@ protected function removePrefixFromKey(string $key): string
373373
return $key;
374374
}
375375

376-
return substr($key, strlen($this->redis->prefix('')));
376+
return substr($key, strlen($this->redis->getOption(RedisClient::OPT_PREFIX)));
377377
}
378378

379379
/**
@@ -483,7 +483,7 @@ protected function collectGauges(bool $sortMetrics = true): array
483483
sort($keys);
484484
$gauges = [];
485485
foreach ($keys as $key) {
486-
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->prefix('')));
486+
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->getOption(RedisClient::OPT_PREFIX) ?? ''));
487487
if (! isset($raw['__meta'])) {
488488
continue;
489489
}
@@ -525,7 +525,7 @@ protected function collectCounters(bool $sortMetrics = true): array
525525
sort($keys);
526526
$counters = [];
527527
foreach ($keys as $key) {
528-
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->prefix('')));
528+
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->getOption(RedisClient::OPT_PREFIX) ?? ''));
529529
if (! isset($raw['__meta'])) {
530530
continue;
531531
}

src/Prometheus/Storage/Redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function fromExistingConnection(\Redis $redis): self
4848
}
4949

5050
$self = new self;
51-
$self->redis = new PHPRedis($redis, self::$defaultOptions);
51+
$self->redis = PHPRedis::fromExistingConnection($redis, self::$defaultOptions);
5252

5353
return $self;
5454
}

src/Prometheus/Storage/RedisClients/PHPRedis.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public static function create(array $options): self
4242
return new self($redis, $options);
4343
}
4444

45+
/**
46+
* @param mixed[] $options
47+
*/
48+
public static function fromExistingConnection(\Redis $redis, array $options): self
49+
{
50+
$self = new self($redis, $options);
51+
$self->connectionInitialized = true;
52+
53+
return $self;
54+
}
55+
4556
public function getOption(int $option): mixed
4657
{
4758
return $this->redis->getOption($option);
@@ -96,11 +107,6 @@ public function del(array|string $key, string ...$other_keys): void
96107
}
97108
}
98109

99-
public function prefix(string $key): string
100-
{
101-
return $this->redis->_prefix($key);
102-
}
103-
104110
/**
105111
* @throws StorageException
106112
*/

src/Prometheus/Storage/RedisClients/Predis.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ public function del(array|string $key, string ...$other_keys): void
120120
$this->client->del($key, ...$other_keys);
121121
}
122122

123-
public function prefix(string $key): string
124-
{
125-
return $this->getOption(RedisClient::OPT_PREFIX).$key;
126-
}
127-
128123
public function ensureOpenConnection(): void
129124
{
130125
// Predis doesn't require to trigger connection

src/Prometheus/Storage/RedisClients/RedisClient.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,5 @@ public function get(string $key): mixed;
4545
*/
4646
public function del(array|string $key, string ...$other_keys): void;
4747

48-
public function prefix(string $key): string;
49-
5048
public function ensureOpenConnection(): void;
5149
}

0 commit comments

Comments
 (0)