Skip to content

Add support for rediss and phpredis #1297

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 1 commit into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions pkg/redis/PhpRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function connect(): void
return;
}

$supportedSchemes = ['redis', 'tcp', 'unix'];
$supportedSchemes = ['redis', 'rediss', 'tcp', 'unix'];
if (false == in_array($this->config['scheme'], $supportedSchemes, true)) {
throw new \LogicException(sprintf(
'The given scheme protocol "%s" is not supported by php extension. It must be one of "%s"',
Expand All @@ -107,9 +107,11 @@ public function connect(): void

$connectionMethod = $this->config['persistent'] ? 'pconnect' : 'connect';

$host = $this->config['scheme'] === 'rediss' ? 'tls://' . $this->config['host'] : $this->config['host'];

$result = call_user_func(
[$this->redis, $connectionMethod],
'unix' === $this->config['scheme'] ? $this->config['path'] : $this->config['host'],
'unix' === $this->config['scheme'] ? $this->config['path'] : $host,
$this->config['port'],
$this->config['timeout'],
$this->config['persistent'] ? ($this->config['phpredis_persistent_id'] ?? null) : null,
Expand Down
32 changes: 23 additions & 9 deletions pkg/redis/Tests/RedisConnectionFactoryConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public function testCouldBeCreatedWithRedisInstance()
$this->assertSame($redisMock, $context->getRedis());
}

public function testThrowIfRedissConnectionUsedWithPhpRedisExtension()
{
$factory = new RedisConnectionFactory('rediss+phpredis:?lazy=0');

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The given scheme protocol "rediss" is not supported by php extension. It must be one of "redis", "tcp", "unix"');
$factory->createContext();
}

/**
* @dataProvider provideConfigs
*
Expand Down Expand Up @@ -273,6 +264,29 @@ public static function provideConfigs()
],
];

//check tls connection for predis library
yield [
'rediss+phpredis://localhost:1234?foo=bar&async=1',
[
'host' => 'tls://localhost',
'scheme' => 'rediss',
'port' => 1234,
'timeout' => 5.,
'database' => null,
'password' => null,
'scheme_extensions' => ['phpredis'],
'path' => null,
'async' => true,
'persistent' => false,
'lazy' => true,
'read_write_timeout' => null,
'predis_options' => null,
'ssl' => null,
'foo' => 'bar',
'redelivery_delay' => 300,
],
];

yield [
['host' => 'localhost', 'port' => 1234, 'foo' => 'bar'],
[
Expand Down