diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 41fec07..be5492a 100755 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -109,7 +109,8 @@ class Resque_Redis /** * @param string|array $server A DSN or array - * @param int $database A database number to select + * @param int $database A database number to select. However, if we find a valid database number in the DSN the + * DSN-supplied value will be used instead and this parameter is ignored. */ public function __construct($server, $database = null) { @@ -134,7 +135,7 @@ class Resque_Redis } // If we have found a database in our DSN, use it instead of the `$database` - // value passed into the constructor + // value passed into the constructor. if ($dsnDatabase !== false) { $database = $dsnDatabase; $this->database = $database; diff --git a/test/Resque/Tests/DsnTest.php b/test/Resque/Tests/DsnTest.php index 2fc6654..7e483a3 100755 --- a/test/Resque/Tests/DsnTest.php +++ b/test/Resque/Tests/DsnTest.php @@ -21,21 +21,21 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost', array( 'localhost', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('localhost:1234', array( 'localhost', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -49,14 +49,14 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://foobar', array( 'foobar', Resque_Redis::DEFAULT_PORT, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), array('redis://foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array(), )), @@ -67,10 +67,17 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase false, false, array(), )), + array('redis://foobar:1234/0', array( + 'foobar', + 1234, + 0, + false, false, + array(), + )), array('redis://user@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array(), )), @@ -84,35 +91,35 @@ class Resque_Tests_DsnTest extends Resque_Tests_TestCase array('redis://user:pass@foobar:1234', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array(), )), array('redis://user:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://:pass@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, 'pass', array('x' => 'y', 'a' => 'b'), )), array('redis://user@foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, 'user', false, array('x' => 'y', 'a' => 'b'), )), array('redis://foobar:1234?x=y&a=b', array( 'foobar', 1234, - Resque_Redis::DEFAULT_DATABASE, + false, false, false, array('x' => 'y', 'a' => 'b'), )),