8000 [Cache] backport type fixes · symfony/cache@8e1c1f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e1c1f9

Browse files
[Cache] backport type fixes
1 parent 5b478f2 commit 8e1c1f9

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

Adapter/RedisAdapter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
15+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
16+
use Symfony\Component\Cache\Traits\RedisProxy;
1517
use Symfony\Component\Cache\Traits\RedisTrait;
1618

1719
class RedisAdapter extends AbstractAdapter
1820
{
1921
use RedisTrait;
2022

2123
/**
22-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
23-
* @param string $namespace The default namespace
24-
* @param int $defaultLifetime The default lifetime
24+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
25+
* @param string $namespace The default namespace
26+
* @param int $defaultLifetime The default lifetime
2527
*/
26-
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
28+
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
2729
{
28-
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
30+
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
2931
}
3032
}

Adapter/RedisTagAwareAdapter.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
2121
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
2222
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
23+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
24+
use Symfony\Component\Cache\Traits\RedisProxy;
2325
use Symfony\Component\Cache\Traits\RedisTrait;
2426

2527
/**
@@ -57,18 +59,18 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
5759
private $redisEvictionPolicy;
5860

5961
/**
60-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
61-
* @param string $namespace The default namespace
62-
* @param int $defaultLifetime The default lifetime
62+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
63+
* @param string $namespace The default namespace
64+
* @param int $defaultLifetime The default lifetime
6365
*/
64-
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
66+
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
6567
{
66-
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
67-
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, \get_class($redisClient->getConnection())));
68+
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
69+
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, \get_class($redis->getConnection())));
6870
}
6971

70-
if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) {
71-
$compression = $redisClient->getOption(\Redis::OPT_COMPRESSION);
72+
if (\defined('Redis::OPT_COMPRESSION') && ($redis instanceof \Redis || $redis instanceof \RedisArray || $redis instanceof \RedisCluster)) {
73+
$compression = $redis->getOption(\Redis::OPT_COMPRESSION);
7274

7375
foreach (\is_array($compression) ? $compression : [$compression] as $c) {
7476
if (\Redis::COMPRESSION_NONE !== $c) {
@@ -77,7 +79,7 @@ public function __construct($redisClient, string $namespace = '', int $defaultLi
7779
}
7880
}
7981

80-
$this->init($redisClient, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
82+
$this->init($redis, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
8183
}
8284

8385
/**

CacheItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getPreviousTags(): array
163163
/**
164164
* Validates a cache key according to PSR-6.
165165
*
166-
* @param string $key The key to validate
166+
* @param mixed $key The key to validate
167167
*
168168
* @throws InvalidArgumentException When $key is not valid
169169
*/

Simple/RedisCache.php

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

1414
use Symfony\Component\Cache\Adapter\RedisAdapter;
1515
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
16+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
17+
use Symfony\Component\Cache\Traits\RedisProxy;
1618
use Symfony\Component\Cache\Traits\RedisTrait;
1719
use Symfony\Contracts\Cache\CacheInterface;
1820

@@ -26,10 +28,10 @@ class RedisCache extends AbstractCache
2628
use RedisTrait;
2729

2830
/**
29-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
31+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
3032
*/
31-
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
33+
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
3234
{
33-
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
35+
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
3436
}
3537
}

Traits/RedisTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@ trait RedisTrait
4747
private $marshaller;
4848

4949
/**
50-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
50+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
5151
*/
52-
private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
52+
private function init($redis, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
5353
{
5454
parent::__construct($namespace, $defaultLifetime);
5555

5656
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
5757
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
5858
}
5959

60-
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
61-
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)));
60+
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
61+
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis)));
6262
}
6363

64-
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {
65-
$options = clone $redisClient->getOptions();
64+
if ($redis instanceof \Predis\ClientInterface && $redis->getOptions()->exceptions) {
65+
$options = clone $redis->getOptions();
6666
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
67-
$redisClient = new $redisClient($redisClient->getConnection(), $options);
67+
$redis = new $redis($redis->getConnection(), $options);
6868
}
6969

70-
$this->redis = $redisClient;
70+
$this->redis = $redis;
7171
$this->marshaller = $marshaller ?? new DefaultMarshaller();
7272
}
7373

0 commit comments

Comments
 (0)
0