Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #18689 [Cache] Add support for Predis, RedisArray and RedisCl…
…uster (nicolas-grekas) This PR was merged into the 3.1-dev branch. Discussion ---------- [Cache] Add support for Predis, RedisArray and RedisCluster | Q | A | ------------- | --- | Branch? | 3.1 ideally | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- b004243 [Cache] Add support for Predis, RedisArray and RedisCluster
- Loading branch information
Showing
7 changed files
with
220 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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\Cache\Tests\Adapter; | ||
|
||
use Cache\IntegrationTests\CachePoolTest; | ||
use Symfony\Component\Cache\Adapter\RedisAdapter; | ||
|
||
abstract class AbstractRedisAdapterTest extends CachePoolTest | ||
{ | ||
protected static $redis; | ||
|
||
public function createCachePool() | ||
{ | ||
if (defined('HHVM_VERSION')) { | ||
$this->skippedTests['testDeferredSaveWithoutCommit'] = 'Fails on HHVM'; | ||
} | ||
|
||
return new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__)); | ||
} | ||
|
||
public static function setupBeforeClass() | ||
{ | ||
if (!extension_loaded('redis')) { | ||
self::markTestSkipped('Extension redis required.'); | ||
} | ||
if (!@((new \Redis())->connect('127.0.0.1'))) { | ||
$e = error_get_last(); | ||
self::markTestSkipped($e['message']); | ||
} | ||
} | ||
|
||
public static function tearDownAfterClass() | ||
{ | ||
self::$redis->flushDB(); | ||
self::$redis = null; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Symfony/Component/Cache/Tests/Adapter/PredisAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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\Cache\Tests\Adapter; | ||
|
||
use Predis\Connection\StreamConnection; | ||
use Symfony\Component\Cache\Adapter\RedisAdapter; | ||
|
||
class PredisAdapterTest extends AbstractRedisAdapterTest | ||
{ | ||
public static function setupBeforeClass() | ||
{ | ||
parent::setupBeforeClass(); | ||
self::$redis = new \Predis\Client(); | ||
} | ||
|
||
public function testCreateConnection() | ||
{ | ||
$redis = RedisAdapter::createConnection('redis://localhost/1', array('class' => \Predis\Client::class, 'timeout' => 3)); | ||
$this->assertInstanceOf(\Predis\Client::class, $redis); | ||
|
||
$connection = $redis->getConnection(); | ||
$this->assertInstanceOf(StreamConnection::class, $connection); | ||
|
||
$params = array( | ||
'scheme' => 'tcp', | ||
'host' => 'localhost', | ||
'path' => '', | ||
'dbindex' => '1', | ||
'port' => 6379, | ||
'class' => 'Predis\Client', | ||
'timeout' => 3, | ||
'persistent' => 0, | ||
'read_timeout' => 0, | ||
'retry_interval' => 0, | ||
'database' => '1', | ||
'password' => null, | ||
); | ||
$this->assertSame($params, $connection->getParameters()->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Symfony/Component/Cache/Tests/Adapter/RedisArrayAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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\Cache\Tests\Adapter; | ||
|
||
class RedisArrayAdapterTest extends AbstractRedisAdapterTest | ||
{ | ||
public static function setupBeforeClass() | ||
{ | ||
parent::setupBeforeClass(); | ||
if (!class_exists('RedisArray')) { | ||
self::markTestSkipped('The RedisArray class is required.'); | ||
} | ||
self::$redis = new \RedisArray(array('localhost'), array('lazy_connect' => true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters