Skip to content

Commit 6f306e9

Browse files
Backward compatiblity with older redis versions (#133)
* Redis(NG) adapter: Added replicate command for backward compatiblity with redis version < 5 Signed-off-by: Immanuel Klinkenberg <drieschel@yahoo.de> * Fixed blackbox tests Signed-off-by: Immanuel Klinkenberg <drieschel@yahoo.de> * Added PHPStan ignore error lines Signed-off-by: Immanuel Klinkenberg <drieschel@yahoo.de> * Test on multiple redis versions --------- Signed-off-by: Immanuel Klinkenberg <drieschel@yahoo.de> Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>
1 parent 82e42b5 commit 6f306e9

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
os: [ ubuntu-latest ]
1212
php: [ 7.4, 8.0, 8.1, 8.2 ]
1313
dependency-version: [ prefer-lowest, prefer-stable ]
14-
redis-version: [ 6 ]
14+
redis-version: [ 5, 6, 7 ]
1515

16-
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
16+
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} - ${{ matrix.redis-version }}
1717

1818
env:
1919
# The hostname used to communicate with the Redis service container

src/Prometheus/CollectorRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function wipeStorage(): void
8383
*/
8484
public function getMetricFamilySamples(bool $sortMetrics = true): array
8585
{
86-
return $this->storageAdapter->collect($sortMetrics);
86+
return $this->storageAdapter->collect($sortMetrics); /** @phpstan-ignore-line */
8787
}
8888

8989
/**

src/Prometheus/Storage/Redis.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function wipeStorage(): void
123123

124124
$this->redis->eval(
125125
<<<LUA
126+
redis.replicate_commands()
126127
local cursor = "0"
127128
repeat
128129
local results = redis.call('SCAN', cursor, 'MATCH', ARGV[1])

src/Prometheus/Storage/RedisNg.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public function wipeStorage(): void
123123

124124
$this->redis->eval(
125125
<<<LUA
126+
redis.replicate_commands()
126127
local cursor = "0"
127128
repeat
128129
local results = redis.call('SCAN', cursor, 'MATCH', ARGV[1])
@@ -474,7 +475,7 @@ private function collectHistograms(): array
474475
*
475476
* @return string
476477
*/
477-
private function removePrefixFromKey(string $key): string
478+
private function removePrefixFromKey(string $key): string /** @phpstan-ignore-line */
478479
{
479480
// @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int
480481
if ($this->redis->getOption(\Redis::OPT_PREFIX) === null) {

tests/Test/BlackBoxTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function gaugesShouldBeOverwritten(): void
4545

4646
];
4747

48-
Promise\settle($promises)->wait();
48+
Promise\Utils::settle($promises)->wait();
4949
$end = microtime(true);
5050
echo "\ntime: " . ($end - $start) . "\n";
5151

@@ -84,7 +84,7 @@ public function countersShouldIncrementAtomically($increment): void
8484
$n += $increment;
8585
}
8686

87-
Promise\settle($promises)->wait();
87+
Promise\Utils::settle($promises)->wait();
8888
$end = microtime(true);
8989
echo "\ntime: " . ($end - $start) . "\n";
9090

@@ -124,7 +124,7 @@ public function histogramsShouldIncrementAtomically(): void
124124
$this->client->getAsync('/examples/some_histogram.php?c=9&adapter=' . $this->adapter),
125125
];
126126

127-
Promise\settle($promises)->wait();
127+
Promise\Utils::settle($promises)->wait();
128128
$end = microtime(true);
129129
echo "\ntime: " . ($end - $start) . "\n";
130130

@@ -168,7 +168,7 @@ public function summariesShouldIncrementAtomically(): void
168168
$this->client->getAsync('/examples/some_summary.php?c=10&adapter=' . $this->adapter),
169169
];
170170

171-
Promise\settle($promises)->wait();
171+
Promise\Utils::settle($promises)->wait();
172172
$end = microtime(true);
173173
echo "\ntime: " . ($end - $start) . "\n";
174174

0 commit comments

Comments
 (0)