Skip to content

Commit 4eef648

Browse files
BrianMwitLink1515
authored andcommitted
RedisTagAwareAdapter Add Predis2 Interface checks (fix #60050)
1 parent 2e80bee commit 4eef648

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Predis\Connection\Aggregate\ClusterInterface;
1515
use Predis\Connection\Aggregate\PredisCluster;
1616
use Predis\Connection\Aggregate\ReplicationInterface;
17+
use Predis\Connection\Replication\ReplicationInterface as Predis2ReplicationInterface;
1718
use Predis\Response\ErrorInterface;
1819
use Predis\Response\Status;
1920
use Relay\Relay;
@@ -286,9 +287,16 @@ private function getRedisEvictionPolicy(): string
286287

287288
$hosts = $this->getHosts();
288289
$host = reset($hosts);
289-
if ($host instanceof \Predis\Client && $host->getConnection() instanceof ReplicationInterface) {
290+
if ($host instanceof \Predis\Client) {
291+
$connection = $host->getConnection();
292+
290293
// Predis supports info command only on the master in replication environments
291-
$hosts = [$host->getClientFor('master')];
294+
if ($connection instanceof ReplicationInterface) {
295+
$hosts = [$host->getClientFor('master')];
296+
} elseif ($connection instanceof Predis2ReplicationInterface) {
297+
$connection->switchToMaster();
298+
$hosts = [$host];
299+
}
292300
}
293301

294302
foreach ($hosts as $host) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Tests\Adapter;
13+
14+
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Cache\Adapter\RedisTagAwareAdapter;
16+
17+
/**
18+
* @group integration
19+
*/
20+
class PredisTagAwareReplicationAdapterTest extends PredisRedisReplicationAdapterTest
21+
{
22+
use TagAwareTestTrait;
23+
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
28+
}
29+
30+
public function createCachePool(int $defaultLifetime = 0, ?string $testMethod = null): CacheItemPoolInterface
31+
{
32+
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
33+
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
34+
35+
return $adapter;
36+
}
37+
}

0 commit comments

Comments
 (0)