Browse Source

#7794 Fix Redis DSN configuration.

Paolo Cuffiani 10 years ago
parent
commit
e4cbf57a84
2 changed files with 36 additions and 0 deletions
  1. 4 0
      src/Cache/Engine/RedisEngine.php
  2. 32 0
      tests/TestCase/Cache/Engine/RedisEngineTest.php

+ 4 - 0
src/Cache/Engine/RedisEngine.php

@@ -82,6 +82,10 @@ class RedisEngine extends CacheEngine
             return false;
         }
 
+        if (!empty($config['host'])) {
+            $this->config('server', $config['host']);
+        }
+
         parent::init($config);
         return $this->_connect();
     }

+ 32 - 0
tests/TestCase/Cache/Engine/RedisEngineTest.php

@@ -104,6 +104,38 @@ class RedisEngineTest extends TestCase
     }
 
     /**
+     * testConfigDsn method
+     *
+     * @return void
+     */
+    public function testConfigDsn()
+    {
+        Cache::config('redis_dsn', [
+            'url' => 'redis://localhost:6379?database=1&prefix=redis_'
+        ]);
+
+        $config = Cache::engine('redis_dsn')->config();
+        $expecting = [
+            'prefix' => 'redis_',
+            'duration' => 3600,
+            'probability' => 100,
+            'groups' => [],
+            'server' => 'localhost',
+            'port' => 6379,
+            'timeout' => 0,
+            'persistent' => true,
+            'password' => false,
+            'database' => '1',
+            'unix_socket' => false,
+            'host' => 'localhost',
+            'scheme' => 'redis',
+        ];
+        $this->assertEquals($expecting, $config);
+
+        Cache::drop('redis_dsn');
+    }
+
+    /**
      * testConnect method
      *
      * @return void