Bladeren bron

Change format required for URI strings when using "unix" scheme.

Instead of using "unix://" you should just use "unix:":

  $old = 'unix:///path/to/redis.sock';
  $new = 'unix:/path/to/redis.sock';

The old format should be considered obsolete and will not be supported
starting from the next major release of Predis.
Meh
Daniele Alessandri 9 jaren geleden
bovenliggende
commit
3dfe62a5b5
4 gewijzigde bestanden met toevoegingen van 35 en 5 verwijderingen
  1. 5 0
      CHANGELOG.md
  2. 8 0
      README.md
  3. 4 3
      src/Connection/Parameters.php
  4. 18 2
      tests/Predis/Connection/ParametersTest.php

+ 5 - 0
CHANGELOG.md

@@ -13,6 +13,11 @@ v1.1.0 (2015-xx-xx)
   is needed to prevent confusion with how `path` is used to select a database
   when using the `redis` scheme.
 
+- Changed how Predis handles URI strings in the context of UNIX domain sockets:
+  `unix:///path/to/socket` should be used now instead of `unix:/path/to/socket`
+  (note the lack of a double slash after the scheme). The old format should be
+  considered obsolete and will not be supported from the next major release.
+
 - Added support for default connection parameters in `Predis\Connection\Factory`
   augmenting the user-supplied parameters used to create new connections.
    but they do not override specific parameters when already defined.

+ 8 - 0
README.md

@@ -95,6 +95,14 @@ $client = new Predis\Client([
 $client = new Predis\Client('tcp://10.0.0.1:6379');
 ```
 
+It is also possible to use UNIX domain sockets when connecting to local Redis instances, parameters
+must use the `unix` scheme and specify a path for the socket file:
+
+```php
+$client = new Predis\Client(['scheme' => 'unix', 'path' => '/path/to/redis.sock']);
+$client = new Predis\Client('unix:/path/to/redis.sock');
+```
+
 The client can leverage TLS/SSL encryption to connect to secured remote Redis instances without the
 the need to configure an SSL proxy like stunnel. This can be useful when connecting to nodes run by
 various cloud hosting providers. Encryption can be enabled with the use the `tls` scheme along with

+ 4 - 3
src/Connection/Parameters.php

@@ -78,9 +78,10 @@ class Parameters implements ParametersInterface
             return static::parseIANA($uri);
         }
 
-        if (stripos($uri, 'unix') === 0) {
-            // Hack to support URIs for UNIX sockets with minimal effort.
-            $uri = str_ireplace('unix:///', 'unix://localhost/', $uri);
+        if (stripos($uri, 'unix://') === 0) {
+            // parse_url() can parse unix:/path/to/sock so we do not need the
+            // unix:///path/to/sock hack, we will support it anyway until 2.0.
+            $uri = str_ireplace('unix://', 'unix:', $uri);
         }
 
         if (!$parsed = parse_url($uri)) {

+ 18 - 2
tests/Predis/Connection/ParametersTest.php

@@ -192,13 +192,29 @@ class ParametersTest extends PredisTestCase
     /**
      * @group disconnected
      */
-    public function testParsingURIWithUnixDomain()
+    public function testParsingURIWithUnixDomainSocket()
     {
         $uri = 'unix:///tmp/redis.sock?timeout=0.5&persistent=1';
 
         $expected = array(
             'scheme' => 'unix',
-            'host' => 'localhost',
+            'path' => '/tmp/redis.sock',
+            'timeout' => '0.5',
+            'persistent' => '1',
+        );
+
+        $this->assertSame($expected, Parameters::parse($uri));
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testParsingURIWithUnixDomainSocketOldWay()
+    {
+        $uri = 'unix:/tmp/redis.sock?timeout=0.5&persistent=1';
+
+        $expected = array(
+            'scheme' => 'unix',
             'path' => '/tmp/redis.sock',
             'timeout' => '0.5',
             'persistent' => '1',