10000 [Cache] Add Redis Relay support by ostrolucky · Pull Request #48930 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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 6 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Semaphore] Accept Relay connection
  • Loading branch information
ostrolucky committed Jan 24, 2023
commit 1d7b4093991257f7ece5b1abc18f7b5f3de9e098
5 changes: 5 additions & 0 deletions src/Symfony/Component/Semaphore/CHANGELOG.md
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

5.3
---

Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Semaphore/Store/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Semaphore\Store;

use Relay\Relay;
use Symfony\Component\Semaphore\Exception\InvalidArgumentException;
use Symfony\Component\Semaphore\Exception\SemaphoreAcquiringException;
use Symfony\Component\Semaphore\Exception\SemaphoreExpiredException;
Expand All @@ -26,7 +27,7 @@
class RedisStore implements PersistingStoreInterface
{
public function __construct(
private \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis,
private \Redis|Relay|\RedisArray|\RedisCluster|\Predis\ClientInterface $redis,
) {
}

Expand Down Expand Up @@ -157,7 +158,7 @@ public function exists(Key $key): bool

private function evaluate(string $script, string $resource, array $args): mixed
{
if ($this->redis instanceof \Redis || $this->redis instanceof \RedisCluster) {
if ($this->redis instanceof \Redis || $this->redis instanceof Relay || $this->redis instanceof \RedisCluster) {
return $this->redis->eval($script, array_merge([$resource], $args), 1);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Semaphore/Store/StoreFactory.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Semaphore\Store;

use Relay\Relay;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Semaphore\Exception\InvalidArgumentException;
use Symfony\Component\Semaphore\PersistingStoreInterface;
Expand All @@ -26,14 +27,14 @@ public static function createStore(#[\SensitiveParameter] object|string $connect
{
switch (true) {
case $connection instanceof \Redis:
case $connection instanceof Relay:
case $connection instanceof \RedisArray:
case $connection instanceof \RedisCluster:
case $connection instanceof \Predis\ClientInterface:
return new RedisStore($connection);

case !\is_string($connection):
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection::class));

case str_starts_with($connection, 'redis://'):
case str_starts_with($connection, 'rediss://'):
if (!class_exists(AbstractAdapter::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Semaphore\Tests\Store;

use Relay\Relay;
use Symfony\Component\Semaphore\PersistingStoreInterface;
use Symfony\Component\Semaphore\Store\RedisStore;

Expand All @@ -19,7 +20,7 @@
*/
abstract class AbstractRedisStoreTest extends AbstractStoreTest
{
abstract protected function getRedisConnection(): \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface;
abstract protected function getRedisConnection(): \Redis|Relay|\RedisArray|\RedisCluster|\Predis\ClientInterface;

public function getStore(): PersistingStoreInterface
{
Expand Down
40 changes: 40 additions & 0 deletions src/Symfony/Component/Semaphore/Tests/Store/RelayStoreTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Semaphore\Tests\Store;

use PHPUnit\Framework\SkippedTestSuiteError;
use Relay\Relay;

/**
* @requires extension relay
*/
class RelayStoreTest extends AbstractRedisStoreTest
{
protected function setUp(): void
{
$this->getRedisConnection()->flushDB();
}

public static function setUpBeforeClass(): void
{
try {
new Relay(...explode(':', getenv('REDIS_HOST')));
} catch (\Relay\Exception $e) {
throw new SkippedTestSuiteError($e->getMessage());
}
}

protected function getRedisConnection(): Relay
{
return new Relay(...explode(':', getenv('REDIS_HOST')));
}
}
0