From c623e47ffd77f5b6a51c3014c53d67f4212745da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Thu, 30 Jun 2022 05:41:16 +0200 Subject: [PATCH] Revert "Replace redis keys to scan (#91)" This reverts commit 918b9962f0d5f2ecf401aa99b334a1620b6aeffe. --- src/Prometheus/Storage/Redis.php | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index 60deaf9c..8b626171 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -485,7 +485,7 @@ private function collectSummaries(): array { $math = new Math(); $summaryKey = self::$prefix . Summary::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX; - $keys = $this->getRedisKeys($summaryKey . ':*:meta'); + $keys = $this->redis->keys($summaryKey . ':*:meta'); $summaries = []; foreach ($keys as $metaKeyWithPrefix) { @@ -506,7 +506,7 @@ private function collectSummaries(): array 'samples' => [], ]; - $values = $this->getRedisKeys($summaryKey . ':' . $metaData['name'] . ':*:value'); + $values = $this->redis->keys($summaryKey . ':' . $metaData['name'] . ':*:value'); foreach ($values as $valueKeyWithPrefix) { $valueKey = $this->removePrefixFromKey($valueKeyWithPrefix); $rawValue = $this->redis->get($valueKey); @@ -518,7 +518,7 @@ private function collectSummaries(): array $decodedLabelValues = $this->decodeLabelValues($encodedLabelValues); $samples = []; - $sampleValues = $this->getRedisKeys($summaryKey . ':' . $metaData['name'] . ':' . $encodedLabelValues . ':value:*'); + $sampleValues = $this->redis->keys($summaryKey . ':' . $metaData['name'] . ':' . $encodedLabelValues . ':value:*'); foreach ($sampleValues as $sampleValueWithPrefix) { $sampleValue = $this->removePrefixFromKey($sampleValueWithPrefix); $samples[] = (float) $this->redis->get($sampleValue); @@ -642,31 +642,6 @@ private function getRedisCommand(int $cmd): string } } - /** - * @param string $pattern - * @return mixed[] - */ - private function getRedisKeys(string $pattern): array - { - $prefix = $this->redis->getOption(\Redis::OPT_PREFIX); - $optScan = $this->redis->getOption(\Redis::OPT_SCAN); - - $cursor = null; - $result = []; - if ($optScan === \Redis::SCAN_RETRY) { - while ($tmpKeys = $this->redis->scan($cursor, $prefix . $pattern)) { - $result = array_merge($result, $tmpKeys); - } - } else { - do { - $tmpKeys = $this->redis->scan($cursor, $prefix . $pattern); - $result = is_array($tmpKeys) ? array_merge($result, $tmpKeys) : $result; - } while ($cursor > 0); - } - - return $result; - } - /** * @param mixed[] $data * @return string