Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2ecea0

Browse files
michaelperrinnicolas-grekas
authored andcommitted
[HttpFoundation] Allow RedisCluster class for RedisSessionHandler
1 parent3ac90c1 commitd2ecea0

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,20 @@ class RedisSessionHandler extends AbstractSessionHandler
3333
* List of available options:
3434
* * prefix: The prefix to use for the keys in order to avoid collision on the Redis server.
3535
*
36-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redis
37-
* @param array $options An associative array of options
36+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\Client|RedisProxy $redis
37+
* @param array$options An associative array of options
3838
*
3939
* @throws \InvalidArgumentException When unsupported client or options are passed
4040
*/
4141
publicfunction__construct($redis,array$options =array())
4242
{
43-
if (!$redisinstanceof \Redis && !$redisinstanceof \RedisArray && !$redisinstanceof \Predis\Client && !$redisinstanceof RedisProxy) {
43+
if (
44+
!$redisinstanceof \Redis &&
45+
!$redisinstanceof \RedisArray &&
46+
!$redisinstanceof \RedisCluster &&
47+
!$redisinstanceof \Predis\Client &&
48+
!$redisinstanceof RedisProxy
49+
) {
4450
thrownew \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)));
4551
}
4652

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/AbstractRedisSessionHandlerTestCase.php‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ abstract class AbstractRedisSessionHandlerTestCase extends TestCase
3232
*/
3333
protected$redisClient;
3434

35-
/**
36-
* @var \Redis
37-
*/
38-
protected$validator;
39-
4035
/**
4136
* @return \Redis|\RedisArray|\RedisCluster|\Predis\Client
4237
*/
@@ -52,9 +47,6 @@ protected function setUp()
5247

5348
$host =getenv('REDIS_HOST') ?:'localhost';
5449

55-
$this->validator =new \Redis();
56-
$this->validator->connect($host);
57-
5850
$this->redisClient =$this->createRedisClient($host);
5951
$this->storage =newRedisSessionHandler(
6052
$this->redisClient,
@@ -154,24 +146,24 @@ public function getOptionFixtures(): array
154146
protectedfunctionsetFixture($key,$value,$ttl =null)
155147
{
156148
if (null !==$ttl) {
157-
$this->validator->setex($key,$ttl,$value);
149+
$this->redisClient->setex($key,$ttl,$value);
158150
}else {
159-
$this->validator->set($key,$value);
151+
$this->redisClient->set($key,$value);
160152
}
161153
}
162154

163155
protectedfunctiongetFixture($key)
164156
{
165-
return$this->validator->get($key);
157+
return$this->redisClient->get($key);
166158
}
167159

168160
protectedfunctionhasFixture($key):bool
169161
{
170-
return$this->validator->exists($key);
162+
return$this->redisClient->exists($key);
171163
}
172164

173165
protectedfunctionfixtureTtl($key):int
174166
{
175-
return$this->validator->ttl($key);
167+
return$this->redisClient->ttl($key);
176168
}
177169
}

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
1717
{
1818
protectedfunctioncreateRedisClient(string$host):Client
1919
{
20-
returnnewClient(array(array('host' =>$host)));
20+
returnnewClient(array(array('host' =>$host)));
2121
}
2222
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\HttpFoundation\Tests\Session\Storage\Handler;
13+
14+
class RedisClusterSessionHandlerTestextends AbstractRedisSessionHandlerTestCase
15+
{
16+
publicstaticfunctionsetupBeforeClass()
17+
{
18+
if (!class_exists('RedisCluster')) {
19+
self::markTestSkipped('The RedisCluster class is required.');
20+
}
21+
22+
if (!$hosts =getenv('REDIS_CLUSTER_HOSTS')) {
23+
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
24+
}
25+
}
26+
27+
protectedfunctioncreateRedisClient(string$host):\RedisCluster
28+
{
29+
returnnew \RedisCluster(null,explode('',getenv('REDIS_CLUSTER_HOSTS')));
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp