-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #48930 [Cache] Add Redis Relay support (ostrolucky)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Cache] Add Redis Relay support | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? |no | Tickets | | License | MIT | Doc PR | This PR adds support for [Relay](https://relay.so/), a next-gen Redis client written in C by the makers of PhpRedis and Predis. It’s built as a drop-in replacement for PhpRedis with a backwards compatible interface for easy adoption. Relay is significantly faster than existing clients by leveraging Redis 6's client-side-caching. While Relay is still on 0.x (pending the addition of cluster support in a few weeks for a 1.0 tag), it’s interface is stable and it’s heavily used in production deployments. Similarly, I've also added Relay support to most popular symfony redis bundle, [snc/redis-bundle](snc/SncRedisBundle#688). But to be able to support these new Redis instances in Symfony components as a Cache, Lock and so on, support had to be added here as well. Since method and constant declarations are compatible with PhpRedis, I've opted into reusing most of the code instead of creating completely new adapters, similarly as was done in case of Predis+PhpRedis. At the same time, I made it a goal not having to have PhpRedis installed in case somebody wishes to use Relay, which explains things like conditional fetch of value constants. Commits ------- c1e5035 [VarDumper] Add Relay support 327969e [redis-messenger] Add Relay support 1d7b409 [Semaphore] Accept Relay connection 0366a32 [HttpFoundation] Accept Relay connection a4c2ca8 [Lock] Accept Relay connection 4173c38 [Cache] Add Relay support
- Loading branch information
Showing
35 changed files
with
1,715 additions
and
96 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
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
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
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
6.3 | ||
--- | ||
|
||
* Add support for Relay PHP extension for Redis | ||
|
||
6.1 | ||
--- | ||
|
||
|
42 changes: 42 additions & 0 deletions
42
src/Symfony/Component/Cache/Tests/Adapter/RelayAdapterSentinelTest.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,42 @@ | ||
<?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 PHPUnit\Framework\SkippedTestSuiteError; | ||
use Relay\Relay; | ||
use Relay\Sentinel; | ||
use Symfony\Component\Cache\Adapter\AbstractAdapter; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class RelayAdapterSentinelTest extends AbstractRedisAdapterTest | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
if (!class_exists(Sentinel::class)) { | ||
throw new SkippedTestSuiteError('The Relay\Sentinel class is required.'); | ||
} | ||
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) { | ||
throw new SkippedTestSuiteError('REDIS_SENTINEL_HOSTS env var is not defined.'); | ||
} | ||
if (!$service = getenv('REDIS_SENTINEL_SERVICE')) { | ||
throw new SkippedTestSuiteError('REDIS_SENTINEL_SERVICE env var is not defined.'); | ||
} | ||
|
||
self::$redis = AbstractAdapter::createConnection( | ||
'redis:?host['.str_replace(' ', ']&host[', $hosts).']', | ||
['redis_sentinel' => $service, 'prefix' => 'prefix_', 'class' => Relay::class], | ||
); | ||
self::assertInstanceOf(Relay::class, self::$redis); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Symfony/Component/Cache/Tests/Adapter/RelayAdapterTest.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,56 @@ | ||
<?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 PHPUnit\Framework\SkippedTestSuiteError; | ||
use Relay\Relay; | ||
use Symfony\Component\Cache\Adapter\AbstractAdapter; | ||
use Symfony\Component\Cache\Adapter\RedisAdapter; | ||
use Symfony\Component\Cache\Exception\InvalidArgumentException; | ||
use Symfony\Component\Cache\Traits\RelayProxy; | ||
|
||
/** | ||
* @requires extension relay | ||
* | ||
* @group integration | ||
*/ | ||
class RelayAdapterTest extends AbstractRedisAdapterTest | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
try { | ||
new Relay(...explode(':', getenv('REDIS_HOST'))); | ||
} catch (\Relay\Exception $e) { | ||
throw new SkippedTestSuiteError(getenv('REDIS_HOST').': '.$e->getMessage()); | ||
} | ||
self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'), ['lazy' => true, 'class' => Relay::class]); | ||
self::assertInstanceOf(RelayProxy::class, self::$redis); | ||
} | ||
|
||
public function testCreateHostConnection() | ||
{ | ||
$redis = RedisAdapter::createConnection('redis://'.getenv('REDIS_HOST').'?class=Relay\Relay'); | ||
$this->assertInstanceOf(Relay::class, $redis); | ||
$this->assertTrue($redis->isConnected()); | ||
$this->assertSame(0, $redis->getDbNum()); | ||
} | ||
|
||
public function testLazyConnection() | ||
{ | ||
$redis = RedisAdapter::createConnection('redis://nonexistenthost?class=Relay\Relay&lazy=1'); | ||
$this->assertInstanceOf(RelayProxy::class, $redis); | ||
// no exception until now | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Failed to resolve host address'); | ||
$redis->getHost(); // yep, only here exception is thrown | ||
} | ||
} |
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
Oops, something went wrong.