Add support for the 'redis://' scheme in URI strings.

The URI string will be handled following the rules as described by the
the provisional IANA registration document that can be found on IANA's
website: http://www.iana.org/assignments/uri-schemes/prov/redis.
This commit is contained in:
Daniele Alessandri
2015-07-23 17:27:58 +02:00
parent 6a0348fbea
commit baaf26fe5b
14 changed files with 308 additions and 38 deletions
+15 -4
View File
@@ -19,7 +19,7 @@ use Predis\Response\Status as StatusResponse;
* Standard connection to Redis servers implemented on top of PHP's streams.
* The connection parameters supported by this class are:
*
* - scheme: it can be either 'tcp' or 'unix'.
* - scheme: it can be either 'redis', 'tcp' or 'unix'.
* - host: hostname or IP address of the server.
* - port: TCP port of the server.
* - path: path of a UNIX domain socket when scheme is 'unix'.
@@ -52,10 +52,17 @@ class StreamConnection extends AbstractConnection
*/
protected function createResource()
{
$initializer = "{$this->parameters->scheme}StreamInitializer";
$resource = $this->$initializer($this->parameters);
switch ($this->parameters->scheme) {
case 'tcp':
case 'redis':
return $this->tcpStreamInitializer($this->parameters);
return $resource;
case 'unix':
return $this->unixStreamInitializer($this->parameters);
default:
throw new \InvalidArgumentException("Invalid scheme: '{$this->parameters->scheme}'.");
}
}
/**
@@ -110,6 +117,10 @@ class StreamConnection extends AbstractConnection
*/
protected function unixStreamInitializer(ParametersInterface $parameters)
{
if ($scheme === 'unix' && !isset($parameters->path)) {
throw new InvalidArgumentException('Missing UNIX domain socket path.');
}
$uri = "unix://{$parameters->path}";
$flags = STREAM_CLIENT_CONNECT;