-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Allow RedisCluster class for RedisSessionHandler #28251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,20 @@ class RedisSessionHandler extends AbstractSessionHandler | |
* List of available options: | ||
* * prefix: The prefix to use for the keys in order to avoid collision on the Redis server. | ||
* | ||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redis | ||
* @param array $options An associative array of options | ||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client|RedisProxy $redis | ||
* @param array $options An associative array of options | ||
* | ||
* @throws \InvalidArgumentException When unsupported client or options are passed | ||
*/ | ||
public function __construct($redis, array $options = array()) | ||
{ | ||
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \Predis\Client && !$redis instanceof RedisProxy) { | ||
if ( | ||
!$redis instanceof \Redis && | ||
!$redis instanceof \RedisArray && | ||
!$redis instanceof \RedisCluster && | ||
!$redis instanceof \Predis\Client && | ||
!$redis instanceof RedisProxy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you talk about the RedisProxy class? That one is imported at the top of the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right sorry! |
||
) { | ||
throw new \InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, \is_object($redis) ? \get_class($redis) : \gettype($redis))); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler; | ||
|
||
class RedisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCase | ||
{ | ||
public static function setupBeforeClass() | ||
{ | ||
if (!class_exists('RedisCluster')) { | ||
self::markTestSkipped('The RedisCluster class is required.'); | ||
} | ||
|
||
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) { | ||
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.'); | ||
} | ||
} | ||
|
||
protected function createRedisClient(string $host): \RedisCluster | ||
{ | ||
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS'))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas Just to make things easier to see, this is the condition I added