Skip to content

Commit 90d7c9c

Browse files
[Cache] make Redis*Proxy extend Redis*
1 parent c9797f6 commit 90d7c9c

File tree

5 files changed

+8
-32
lines changed

5 files changed

+8
-32
lines changed

Store/RedisStore.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
namespace Symfony\Component\Lock\Store;
1313

1414
use Predis\Response\ServerException;
15-
use Symfony\Component\Cache\Traits\RedisClusterProxy;
16-
use Symfony\Component\Cache\Traits\RedisProxy;
1715
use Symfony\Component\Lock\Exception\InvalidTtlException;
1816
use Symfony\Component\Lock\Exception\LockConflictedException;
1917
use Symfony\Component\Lock\Exception\LockStorageException;
@@ -31,21 +29,18 @@ class RedisStore implements SharedLockStoreInterface
3129
{
3230
use ExpiringStoreTrait;
3331

34-
private \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis;
35-
private float $initialTtl;
3632
private bool $supportTime;
3733

3834
/**
3935
* @param float $initialTtl The expiration delay of locks in seconds
4036
*/
41-
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, float $initialTtl = 300.0)
42-
{
37+
public function __construct(
38+
private \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis,
39+
private float $initialTtl = 300.0,
40+
) {
4341
if ($initialTtl <= 0) {
4442
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
4543
}
46-
47-
$this->redis = $redis;
48-
$this->initialTtl = $initialTtl;
4944
}
5045

5146
public function save(Key $key)
@@ -231,12 +226,7 @@ public function exists(Key $key): bool
231226

232227
private function evaluate(string $script, string $resource, array $args): mixed
233228
{
234-
if (
235-
$this->redis instanceof \Redis ||
236-
$this->redis instanceof \RedisCluster ||
237-
$this->redis instanceof RedisProxy ||
238-
$this->redis instanceof RedisClusterProxy
239-
) {
229+
if ($this->redis instanceof \Redis || $this->redis instanceof \RedisCluster) {
240230
$this->redis->clearLastError();
241231
$result = $this->redis->eval($script, array_merge([$resource], $args), 1);
242232
if (null !== $err = $this->redis->getLastError()) {

Store/StoreFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Symfony\Component\Cache\Adapter\AbstractAdapter;
16-
use Symfony\Component\Cache\Traits\RedisClusterProxy;
17-
use Symfony\Component\Cache\Traits\RedisProxy;
1816
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1917
use Symfony\Component\Lock\PersistingStoreInterface;
2018

@@ -32,8 +30,6 @@ public static function createStore(object|string $connection): PersistingStoreIn
3230
case $connection instanceof \RedisArray:
3331
case $connection instanceof \RedisCluster:
3432
case $connection instanceof \Predis\ClientInterface:
35-
case $connection instanceof RedisProxy:
36-
case $connection instanceof RedisClusterProxy:
3733
return new RedisStore($connection);
3834

3935
case $connection instanceof \Memcached:

Tests/Store/AbstractRedisStoreTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Lock\Tests\Store;
1313

14-
use Symfony\Component\Cache\Traits\RedisClusterProxy;
15-
use Symfony\Component\Cache\Traits\RedisProxy;
1614
use Symfony\Component\Lock\Exception\InvalidArgumentException;
1715
use Symfony\Component\Lock\Exception\LockConflictedException;
1816
use Symfony\Component\Lock\Key;
@@ -87,12 +85,7 @@ public function exists(Key $key)
8785

8886
private function evaluate(string $script, string $resource, array $args)
8987
{
90-
if (
91-
$this->redis instanceof \Redis ||
92-
$this->redis instanceof \RedisCluster ||
93-
$this->redis instanceof RedisProxy ||
94-
$this->redis instanceof RedisClusterProxy
95-
) {
88+
if ($this->redis instanceof \Redis || $this->redis instanceof \RedisCluster) {
9689
return $this->redis->eval($script, array_merge([$resource], $args), 1);
9790
}
9891

Tests/Store/StoreFactoryTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1717
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
18-
use Symfony\Component\Cache\Traits\RedisProxy;
1918
use Symfony\Component\Lock\Store\DoctrineDbalPostgreSqlStore;
2019
use Symfony\Component\Lock\Store\DoctrineDbalStore;
2120
use Symfony\Component\Lock\Store\FlockStore;
@@ -49,9 +48,6 @@ public function validConnections()
4948
if (class_exists(\Redis::class)) {
5049
yield [new \Redis(), RedisStore::class];
5150
}
52-
if (class_exists(RedisProxy::class)) {
53-
yield [$this->createMock(RedisProxy::class), RedisStore::class];
54-
}
5551
yield [new \Predis\Client(), RedisStore::class];
5652
if (class_exists(\Memcached::class)) {
5753
yield [new \Memcached(), MemcachedStore::class];

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"predis/predis": "~1.0"
2525
},
2626
"conflict": {
27-
"doctrine/dbal": "<2.13"
27+
"doctrine/dbal": "<2.13",
28+
"symfony/cache": "<6.2"
2829
},
2930
"autoload": {
3031
"psr-4": { "Symfony\\Component\\Lock\\": "" },

0 commit comments

Comments
 (0)