diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index b10e3f9..730fac8 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -97,8 +97,8 @@ public static function setPrefix(string $prefix): void } /** - * @deprecated use replacement method wipeStorage from Adapter interface * @throws StorageException + * @deprecated use replacement method wipeStorage from Adapter interface */ public function flushRedis(): void { @@ -230,11 +230,11 @@ private function connectToServer(): void if ($this->options['persistent_connections'] !== false) { $connection_successful = $this->redis->pconnect( $this->options['host'], - (int) $this->options['port'], - (float) $this->options['timeout'] + (int)$this->options['port'], + (float)$this->options['timeout'] ); } else { - $connection_successful = $this->redis->connect($this->options['host'], (int) $this->options['port'], (float) $this->options['timeout']); + $connection_successful = $this->redis->connect($this->options['host'], (int)$this->options['port'], (float)$this->options['timeout']); } if (!$connection_successful) { throw new StorageException( @@ -306,7 +306,8 @@ public function updateSummary(array $data): void if (false === $json) { throw new RuntimeException(json_last_error_msg()); } - $this->redis->setNx($metaKey, $json); /** @phpstan-ignore-line */ + $this->redis->setNx($metaKey, $json);/** @phpstan-ignore-line */ + // store value key $valueKey = $summaryKey . ':' . $this->valueKey($data); @@ -314,7 +315,7 @@ public function updateSummary(array $data): void if (false === $json) { throw new RuntimeException(json_last_error_msg()); } - $this->redis->setNx($valueKey, $json); /** @phpstan-ignore-line */ + $this->redis->setNx($valueKey, $json);/** @phpstan-ignore-line */ // trick to handle uniqid collision $done = false; @@ -414,7 +415,7 @@ private function collectHistograms(): array sort($keys); $histograms = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; } @@ -546,7 +547,7 @@ private function collectSummaries(): array $sampleValues = $this->redis->keys($summaryKey . ':' . $metaData['name'] . ':' . $encodedLabelValues . ':value:*'); foreach ($sampleValues as $sampleValueWithPrefix) { $sampleValue = $this->removePrefixFromKey($sampleValueWithPrefix); - $samples[] = (float) $this->redis->get($sampleValue); + $samples[] = (float)$this->redis->get($sampleValue); } if (count($samples) === 0) { @@ -608,7 +609,7 @@ private function collectGauges(bool $sortMetrics = true): array sort($keys); $gauges = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; } @@ -648,7 +649,7 @@ private function collectCounters(bool $sortMetrics = true): array sort($keys); $counters = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; } diff --git a/src/Prometheus/Storage/RedisNg.php b/src/Prometheus/Storage/RedisNg.php index 1a79ef3..a5bfc36 100644 --- a/src/Prometheus/Storage/RedisNg.php +++ b/src/Prometheus/Storage/RedisNg.php @@ -414,7 +414,7 @@ private function collectHistograms(): array sort($keys); $histograms = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; } @@ -597,7 +597,7 @@ private function collectGauges(bool $sortMetrics = true): array sort($keys); $gauges = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; } @@ -637,7 +637,7 @@ private function collectCounters(bool $sortMetrics = true): array sort($keys); $counters = []; foreach ($keys as $key) { - $raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key)); + $raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix(''))); if (!isset($raw['__meta'])) { continue; }