-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Cache] Add Redis Relay support #48930
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4173c38
[Cache] Add Relay support
ostrolucky a4c2ca8
[Lock] Accept Relay connection
ostrolucky 0366a32
[HttpFoundation] Accept Relay connection
ostrolucky 1d7b409
[Semaphore] Accept Relay connection
ostrolucky 327969e
[redis-messenger] Add Relay support
ostrolucky c1e5035
[VarDumper] Add Relay support
ostrolucky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.