Skip to content

Commit c63642e

Browse files
committed
Add support for rediss and phpredis
1 parent dd93f09 commit c63642e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

Diff for: pkg/redis/PhpRedis.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function connect(): void
9494
return;
9595
}
9696

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

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

110+
$host = $this->config['scheme'] === 'rediss' ? 'tls://' . $this->config['host'] : $this->config['host'];
111+
110112
$result = call_user_func(
111113
[$this->redis, $connectionMethod],
112-
'unix' === $this->config['scheme'] ? $this->config['path'] : $this->config['host'],
114+
'unix' === $this->config['scheme'] ? $this->config['path'] : $host,
113115
$this->config['port'],
114116
$this->config['timeout'],
115117
$this->config['persistent'] ? ($this->config['phpredis_persistent_id'] ?? null) : null,

Diff for: pkg/redis/Tests/RedisConnectionFactoryConfigTest.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ public function testCouldBeCreatedWithRedisInstance()
5151
$this->assertSame($redisMock, $context->getRedis());
5252
}
5353

54-
public function testThrowIfRedissConnectionUsedWithPhpRedisExtension()
55-
{
56-
$factory = new RedisConnectionFactory('rediss+phpredis:?lazy=0');
57-
58-
$this->expectException(\LogicException::class);
59-
$this->expectExceptionMessage('The given scheme protocol "rediss" is not supported by php extension. It must be one of "redis", "tcp", "unix"');
60-
$factory->createContext();
61-
}
62-
6354
/**
6455
* @dataProvider provideConfigs
6556
*
@@ -273,6 +264,29 @@ public static function provideConfigs()
273264
],
274265
];
275266

267+
//check tls connection for predis library
268+
yield [
269+
'rediss+phpredis://localhost:1234?foo=bar&async=1',
270+
[
271+
'host' => 'tls://localhost',
272+
'scheme' => 'rediss',
273+
'port' => 1234,
274+
'timeout' => 5.,
275+
'database' => null,
276+
'password' => null,
277+
'scheme_extensions' => ['phpredis'],
278+
'path' => null,
279+
'async' => true,
280+
'persistent' => false,
281+
'lazy' => true,
282+
'read_write_timeout' => null,
283+
'predis_options' => null,
284+
'ssl' => null,
285+
'foo' => 'bar',
286+
'redelivery_delay' => 300,
287+
],
288+
];
289+
276290
yield [
277291
['host' => 'localhost', 'port' => 1234, 'foo' => 'bar'],
278292
[

0 commit comments

Comments
 (0)