Skip to content

Commit

Permalink
bug #37590 Allows RedisClusterProxy instance in Lock RedisStore (jder…
Browse files Browse the repository at this point in the history
…usse)

This PR was merged into the 4.4 branch.

Discussion
----------

Allows RedisClusterProxy instance in Lock RedisStore

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37476
| License       | MIT
| Doc PR        | /

This PR allow clients instance of RedisClusterProxy created by the StoreFactory in #28691 /cc @nicolas-grekas

Commits
-------

8ef63cd Allows RedisClusterProxy instance in Lock RedisStore
  • Loading branch information
nicolas-grekas committed Jul 23, 2020
2 parents 2c84ea2 + 8ef63cd commit 0eae7a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function init($redisClient, string $namespace, int $defaultLifetime, ?Ma
*
* @throws InvalidArgumentException when the DSN is invalid
*
* @return \Redis|\RedisCluster|\Predis\ClientInterface According to the "class" option
* @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
*/
public static function createConnection($dsn, array $options = [])
{
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Lock/Store/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class RedisStore implements StoreInterface
private $initialTtl;

/**
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
* @param float $initialTtl the expiration delay of locks in seconds
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy\Predis\ClientInterface $redisClient
* @param float $initialTtl the expiration delay of locks in seconds
*/
public function __construct($redisClient, float $initialTtl = 300.0)
{
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy) {
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)));
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient 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)));
}

if ($initialTtl <= 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public function validConnections()
}
if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
yield ['redis://localhost', RedisStore::class];
yield ['redis://localhost?lazy=1', RedisStore::class];
yield ['redis://localhost?redis_cluster=1', RedisStore::class];
yield ['redis://localhost?redis_cluster=1&lazy=1', RedisStore::class];
}
if (class_exists(\PDO::class)) {
yield ['sqlite:/tmp/sqlite.db', PdoStore::class];
Expand Down

0 comments on commit 0eae7a6

Please sign in to comment.