diff --git a/pkg/redis/RedisConnectionFactory.php b/pkg/redis/RedisConnectionFactory.php index 3ed90dc5d..0cdbe7caa 100644 --- a/pkg/redis/RedisConnectionFactory.php +++ b/pkg/redis/RedisConnectionFactory.php @@ -50,13 +50,14 @@ public function __construct($config = 'redis:') } $this->config = array_replace($this->defaultConfig(), $config); + $vendor = $this->config['vendor']; $supportedVendors = ['predis', 'phpredis', 'custom']; - if (false == in_array($this->config['vendor'], $supportedVendors, true)) { + if (false == in_array($vendor, $supportedVendors, true)) { throw new \LogicException(sprintf( 'Unsupported redis vendor given. It must be either "%s". Got "%s"', implode('", "', $supportedVendors), - $this->config['vendor'] + $vendor )); } } @@ -116,8 +117,10 @@ private function createRedis() */ private function parseDsn($dsn) { - if (false === strpos($dsn, 'redis:')) { - throw new \LogicException(sprintf('The given DSN "%s" is not supported. Must start with "redis:".', $dsn)); + $unsupportedError = 'The given DSN "%s" is not supported. Must start with "redis:".'; + + if ((false === strpos($dsn, 'redis:')) and (false === strpos($dsn, 'rediss:'))) { + throw new \LogicException(sprintf($unsupportedError, $dsn)); } if (false === $config = parse_url($dsn)) { @@ -131,7 +134,19 @@ private function parseDsn($dsn) $config = array_replace($queryConfig, $config); } - unset($config['query'], $config['scheme']); + if (isset($config['vendor'])) { + $vendor = $config['vendor']; + } else { + $vendor = ""; + } + + + //predis additionaly supports tls as scheme, but it must remain in the $config array + if ($vendor!='predis') { + if ($config['scheme']!='redis') throw new \LogicException(sprintf($unsupportedError, $dsn)); + unset($config['scheme']); + } + unset($config['query']); $config['lazy'] = empty($config['lazy']) ? false : true; $config['persisted'] = empty($config['persisted']) ? false : true; diff --git a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php index cfcdf959b..cec0b1945 100644 --- a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php +++ b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php @@ -125,6 +125,46 @@ public static function provideConfigs() ], ]; + //check normal redis connection for predis library + yield [ + 'redis://localhost:1234?foo=bar&lazy=0&vendor=predis', + [ + 'host' => 'localhost', + 'port' => 1234, + 'timeout' => null, + 'reserved' => null, + 'retry_interval' => null, + 'vendor' => 'predis', + 'persisted' => false, + 'lazy' => false, + 'foo' => 'bar', + 'database' => 0, + 'scheme' => 'redis', + 'redis' => null, + ], + ]; + + //check tls connection for predis library + yield [ + 'rediss://localhost:1234?foo=bar&lazy=0&vendor=predis', + [ + 'host' => 'localhost', + 'port' => 1234, + 'timeout' => null, + 'reserved' => null, + 'retry_interval' => null, + 'vendor' => 'predis', + 'persisted' => false, + 'lazy' => false, + 'foo' => 'bar', + 'database' => 0, + 'scheme' => 'rediss', + 'redis' => null, + ], + ]; + + + yield [ ['host' => 'localhost', 'port' => 1234, 'foo' => 'bar'], [