Skip to content

Commit a682051

Browse files
minor #28255 [travis] enable Redis cluster (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [travis] enable Redis cluster | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Will allow testing #28251 also Commits ------- f245df4 [travis] enable Redis cluster
2 parents 817e7cd + f245df4 commit a682051

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ services:
4141
- memcached
4242
- mongodb
4343
- redis-server
44+
- docker
4445

4546
before_install:
47+
- |
48+
# Start Redis cluster
49+
docker pull grokzen/redis-cluster:4.0.8
50+
docker run -d -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 --name redis-cluster grokzen/redis-cluster:4.0.8
51+
export REDIS_CLUSTER_HOSTS='localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005'
52+
4653
- |
4754
# General configuration
4855
set -e
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
namespace Symfony\Component\Cache\Tests\Adapter;
13+
14+
class RedisClusterAdapterTest extends AbstractRedisAdapterTest
15+
{
16+
public static function setupBeforeClass()
17+
{
18+
if (!class_exists('RedisCluster')) {
19+
self::markTestSkipped('The RedisCluster class is required.');
20+
}
21+
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
22+
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
23+
}
24+
25+
self::$redis = new \RedisCluster(null, explode(' ', $hosts));
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
namespace Symfony\Component\Cache\Tests\Simple;
13+
14+
class RedisClusterCacheTest extends AbstractRedisCacheTest
15+
{
16+
public static function setupBeforeClass()
17+
{
18+
if (!class_exists('RedisCluster')) {
19+
self::markTestSkipped('The RedisCluster class is required.');
20+
}
21+
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
22+
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
23+
}
24+
25+
self::$redis = new \RedisCluster(null, explode(' ', $hosts));
26+
}
27+
}

src/Symfony/Component/Lock/Store/RedisStore.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public function save(Key $key)
5454
$script = '
5555
if redis.call("GET", KEYS[1]) == ARGV[1] then
5656
return redis.call("PEXPIRE", KEYS[1], ARGV[2])
57+
elseif redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2]) then
58+
return 1
5759
else
58-
return redis.call("set", KEYS[1], ARGV[1], "NX", "PX", ARGV[2])
60+
return 0
5961
end
6062
';
6163

@@ -144,7 +146,7 @@ private function evaluate($script, $resource, array $args)
144146
return \call_user_func_array(array($this->redis, 'eval'), array_merge(array($script, 1, $resource), $args));
145147
}
146148

147-
throw new InvalidArgumentException(sprintf('%s() expects been initialized with a Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
149+
throw new InvalidArgumentException(sprintf('%s() expects being initialized with a Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, \is_object($this->redis) ? \get_class($this->redis) : \gettype($this->redis)));
148150
}
149151

150152
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
namespace Symfony\Component\Lock\Tests\Store;
13+
14+
/**
15+
* @author Jérémy Derussé <jeremy@derusse.com>
16+
*
17+
* @requires extension redis
18+
*/
19+
class RedisClusterStoreTest extends AbstractRedisStoreTest
20+
{
21+
public static function setupBeforeClass()
22+
{
23+
if (!class_exists('RedisCluster')) {
24+
self::markTestSkipped('The RedisCluster class is required.');
25+
}
26+
if (!getenv('REDIS_CLUSTER_HOSTS')) {
27+
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
28+
}
29+
}
30+
31+
protected function getRedisConnection()
32+
{
33+
return new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
34+
}
35+
}

0 commit comments

Comments
 (0)