Skip to content

Commit

Permalink
Fixed a bug that meant redis database numbers greater than zero (0) c…
Browse files Browse the repository at this point in the history
…ould 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.
  • Loading branch information
Uyi Ehondor committed Aug 20, 2014
1 parent 9fdcaa2 commit 7d0a9cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/Rhubarb/Connector/Predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 23 additions & 1 deletion tests/library/Rhubarb/PredisTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace RhubarbTests;

use Rhubarb\Connector\Predis as PredisConnector;

/**
* @license http://www.apache.org/licenses/LICENSE-2.0
* Copyright [2012] [Robert Allen]
Expand Down Expand Up @@ -30,7 +32,7 @@
*/
class PredisTest extends \PHPUnit_Framework_TestCase
{

/**
* @group job
*/
Expand Down Expand Up @@ -64,4 +66,24 @@ public function testJobSubmit()
// $this->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());
}
}

0 comments on commit 7d0a9cb

Please sign in to comment.