10000 [Cache] Add server-commands support for Predis Replication Environments · symfony/symfony@2ae5c33 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ae5c33

Browse files
DemigodCodenicolas-grekas
authored andcommitted
[Cache] Add server-commands support for Predis Replication Environments
1 parent 91121ac commit 2ae5c33

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Predis\Connection\Aggregate\ClusterInterface;
1515
use Predis\Connection\Aggregate\PredisCluster;
16+
use Predis\Connection\Aggregate\ReplicationInterface;
1617
use Predis\Response\Status;
1718
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1819
use Symfony\Component\Cache\Exception\LogicException;
@@ -278,7 +279,14 @@ private function getRedisEvictionPolicy(): string
278279
return $this->redisEvictionPolicy;
279280
}
280281

281-
foreach ($this->getHosts() as $host) {
282+
$hosts = $this->getHosts();
283+
$host = reset($hosts);
284+
if ($host instanceof \Predis\Client && $host->getConnection() instanceof ReplicationInterface) {
285+
// Predis supports info command only on the master in replication environments
286+
$hosts = [$host->getClientFor('master')];
287+
}
288+
289+
foreach ($hosts as $host) {
282290
$info = $host->info('Memory');
283291
$info = $info['Memory'] ?? $info;
284292

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Predis\Connection\Aggregate\ClusterInterface;
1515
use Predis\Connection\Aggregate\RedisCluster;
16+
use Predis\Connection\Aggregate\ReplicationInterface;
1617
use Predis\Response\Status;
1718
use Symfony\Component\Cache\Exception\CacheException;
1819
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@@ -367,7 +368,14 @@ protected function doClear($namespace)
367368
$evalArgs = [[$namespace], 0];
368369
}
369370

370-
foreach ($this->getHosts() as $host) {
371+
$hosts = $this->getHosts();
372+
$host = reset($hosts);
373+
if ($host instanceof \Predis\Client && $host->getConnection() instanceof ReplicationInterface) {
374+
// Predis supports info command only on the master in replication environments
375+
$hosts = [$host->getClientFor('master')];
376+
}
377+
378+
foreach ($hosts as $host) {
371379
if (!isset($namespace[0])) {
372380
$cleared = $host->flushDb() && $cleared;
373381
continue;

0 commit comments

Comments
 (0)
0