[Cache] backport type fixes
This commit is contained in:
parent
ba7e97d528
commit
a6a00915c3
2
.github/workflows/integration-tests.yml
vendored
2
.github/workflows/integration-tests.yml
vendored
@ -72,7 +72,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
coverage: "none"
|
coverage: "none"
|
||||||
extensions: "memcached,redis,xsl,ldap"
|
extensions: "memcached,redis,xsl,ldap"
|
||||||
ini-values: "memory_limit=-1"
|
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
|
||||||
php-version: "${{ matrix.php }}"
|
php-version: "${{ matrix.php }}"
|
||||||
|
|
||||||
- name: Load fixtures
|
- name: Load fixtures
|
||||||
|
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@ -46,7 +46,7 @@ jobs:
|
|||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
coverage: "none"
|
coverage: "none"
|
||||||
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1
|
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
|
||||||
php-version: "${{ matrix.php }}"
|
php-version: "${{ matrix.php }}"
|
||||||
extensions: "${{ env.extensions }}"
|
extensions: "${{ env.extensions }}"
|
||||||
tools: flex
|
tools: flex
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
namespace Symfony\Component\Cache\Adapter;
|
namespace Symfony\Component\Cache\Adapter;
|
||||||
|
|
||||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisClusterProxy;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||||
use Symfony\Component\Cache\Traits\RedisTrait;
|
use Symfony\Component\Cache\Traits\RedisTrait;
|
||||||
|
|
||||||
class RedisAdapter extends AbstractAdapter
|
class RedisAdapter extends AbstractAdapter
|
||||||
@ -19,12 +21,12 @@ class RedisAdapter extends AbstractAdapter
|
|||||||
use RedisTrait;
|
use RedisTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
|
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
|
||||||
* @param string $namespace The default namespace
|
* @param string $namespace The default namespace
|
||||||
* @param int $defaultLifetime The default lifetime
|
* @param int $defaultLifetime The default lifetime
|
||||||
*/
|
*/
|
||||||
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||||
{
|
{
|
||||||
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
|
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ use Symfony\Component\Cache\Exception\LogicException;
|
|||||||
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
|
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
|
||||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||||
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
|
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisClusterProxy;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||||
use Symfony\Component\Cache\Traits\RedisTrait;
|
use Symfony\Component\Cache\Traits\RedisTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,18 +59,18 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
|||||||
private $redisEvictionPolicy;
|
private $redisEvictionPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
|
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
|
||||||
* @param string $namespace The default namespace
|
* @param string $namespace The default namespace
|
||||||
* @param int $defaultLifetime The default lifetime
|
* @param int $defaultLifetime The default lifetime
|
||||||
*/
|
*/
|
||||||
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||||
{
|
{
|
||||||
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
|
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
|
||||||
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, \get_class($redisClient->getConnection())));
|
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, \get_class($redis->getConnection())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) {
|
if (\defined('Redis::OPT_COMPRESSION') && ($redis instanceof \Redis || $redis instanceof \RedisArray || $redis instanceof \RedisCluster)) {
|
||||||
$compression = $redisClient->getOption(\Redis::OPT_COMPRESSION);
|
$compression = $redis->getOption(\Redis::OPT_COMPRESSION);
|
||||||
|
|
||||||
foreach (\is_array($compression) ? $compression : [$compression] as $c) {
|
foreach (\is_array($compression) ? $compression : [$compression] as $c) {
|
||||||
if (\Redis::COMPRESSION_NONE !== $c) {
|
if (\Redis::COMPRESSION_NONE !== $c) {
|
||||||
@ -77,7 +79,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->init($redisClient, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
|
$this->init($redis, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,7 +163,7 @@ final class CacheItem implements ItemInterface
|
|||||||
/**
|
/**
|
||||||
* Validates a cache key according to PSR-6.
|
* Validates a cache key according to PSR-6.
|
||||||
*
|
*
|
||||||
* @param string $key The key to validate
|
* @param mixed $key The key to validate
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException When $key is not valid
|
* @throws InvalidArgumentException When $key is not valid
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\Cache\Simple;
|
|||||||
|
|
||||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisClusterProxy;
|
||||||
|
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||||
use Symfony\Component\Cache\Traits\RedisTrait;
|
use Symfony\Component\Cache\Traits\RedisTrait;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
|
||||||
@ -26,10 +28,10 @@ class RedisCache extends AbstractCache
|
|||||||
use RedisTrait;
|
use RedisTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
|
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
|
||||||
*/
|
*/
|
||||||
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||||
{
|
{
|
||||||
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
|
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ trait RedisTrait
|
|||||||
private $marshaller;
|
private $marshaller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
|
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
|
||||||
*/
|
*/
|
||||||
private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
|
private function init($redis, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
|
||||||
{
|
{
|
||||||
parent::__construct($namespace, $defaultLifetime);
|
parent::__construct($namespace, $defaultLifetime);
|
||||||
|
|
||||||
@ -57,17 +57,17 @@ trait RedisTrait
|
|||||||
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
|
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
|
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
|
||||||
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)));
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {
|
if ($redis instanceof \Predis\ClientInterface && $redis->getOptions()->exceptions) {
|
||||||
$options = clone $redisClient->getOptions();
|
$options = clone $redis->getOptions();
|
||||||
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
|
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
|
||||||
$redisClient = new $redisClient($redisClient->getConnection(), $options);
|
$redis = new $redis($redis->getConnection(), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis = $redisClient;
|
$this->redis = $redis;
|
||||||
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,8 +182,10 @@ class ExpressionLanguageTest extends TestCase
|
|||||||
->expects($this->exactly(1))
|
->expects($this->exactly(1))
|
||||||
->method('set')
|
->method('set')
|
||||||
->with($this->isInstanceOf(ParsedExpression::class))
|
->with($this->isInstanceOf(ParsedExpression::class))
|
||||||
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression) {
|
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression, $cacheItemMock) {
|
||||||
$savedParsedExpression = $parsedExpression;
|
$savedParsedExpression = $parsedExpression;
|
||||||
|
|
||||||
|
return $cacheItemMock;
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -191,6 +193,7 @@ class ExpressionLanguageTest extends TestCase
|
|||||||
->expects($this->exactly(1))
|
->expects($this->exactly(1))
|
||||||
->method('save')
|
->method('save')
|
||||||
->with($cacheItemMock)
|
->with($cacheItemMock)
|
||||||
|
->willReturn(true)
|
||||||
;
|
;
|
||||||
|
|
||||||
$expression = 'a + b';
|
$expression = 'a + b';
|
||||||
|
@ -33,20 +33,20 @@ class RedisStore implements StoreInterface
|
|||||||
private $initialTtl;
|
private $initialTtl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redisClient
|
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redis
|
||||||
* @param float $initialTtl the expiration delay of locks in seconds
|
* @param float $initialTtl The expiration delay of locks in seconds
|
||||||
*/
|
*/
|
||||||
public function __construct($redisClient, float $initialTtl = 300.0)
|
public function __construct($redis, float $initialTtl = 300.0)
|
||||||
{
|
{
|
||||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
|
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
|
||||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster, RedisProxy, RedisClusterProxy or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redisClient) ? \get_class($redisClient) : \gettype($redisClient)));
|
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster, RedisProxy, RedisClusterProxy or Predis\ClientInterface, "%s" given.', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($initialTtl <= 0) {
|
if ($initialTtl <= 0) {
|
||||||
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->redis = $redisClient;
|
$this->redis = $redis;
|
||||||
$this->initialTtl = $initialTtl;
|
$this->initialTtl = $initialTtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user