From 7d0a9cb6146a2d61eae8a6268c899a0847a55af1 Mon Sep 17 00:00:00 2001 From: Uyi Ehondor Date: Tue, 20 May 2014 08:47:25 +0100 Subject: [PATCH] Fixed a bug that meant redis database numbers greater than zero (0) could not be used For example If you give the Predis connector a connection dsn similar to 'redis://127.0.0.1:6379/3', the expected behaviour is to use redis database 3, it doesn't. It always uses redis db 0. The fix was to correct a small typo in the Rhubarb/Connector/Predis file. --- library/Rhubarb/Connector/Predis.php | 2 +- tests/library/Rhubarb/PredisTest.php | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/library/Rhubarb/Connector/Predis.php b/library/Rhubarb/Connector/Predis.php index b2922e7..c38fa84 100644 --- a/library/Rhubarb/Connector/Predis.php +++ b/library/Rhubarb/Connector/Predis.php @@ -79,7 +79,7 @@ public function setOptions(array $options) } if (isset($uri['path'])) { $uri['database'] = trim($uri['path'], '/'); - $options['connection']['database'] = isset($uri['databsae']) ? $uri['database'] : null; + $options['connection']['database'] = isset($uri['database']) ? $uri['database'] : null; } $options['connection']['host'] = $uri['host']; $options['connection']['port'] = isset($uri['port']) ? $uri['port'] : 6379; diff --git a/tests/library/Rhubarb/PredisTest.php b/tests/library/Rhubarb/PredisTest.php index 8402f00..68f2a55 100644 --- a/tests/library/Rhubarb/PredisTest.php +++ b/tests/library/Rhubarb/PredisTest.php @@ -1,6 +1,8 @@ assertEquals(2105, $res->get()); } + public function testSetOptionsWhenNonZeroRedisDatabaseNumberIsSpecified() + { + $connector = new PredisConnector(); + $connector->setOptions( + array('connection' => 'redis://127.0.0.1:6379/3') + ); + + $expectedOptions = array( + 'connection' => array( + 'database'=> 3, + 'host' => '127.0.0.1', + 'port' => 6379, + 'login' => null, + 'password' => null + ), + 'options' => array() + ); + + $this->assertEquals($expectedOptions, $connector->getOptions()); + } }