Skip to content

Commit

Permalink
Merge pull request #340 from Erliz/patch-sentinel_db
Browse files Browse the repository at this point in the history
Add database & password parameters support for predis sentinel
  • Loading branch information
snc authored Jun 3, 2017
2 parents 5c2a4ef + 656a317 commit a2ffea7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Client/Predis/Connection/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function setConnectionWrapperClass($class)
*/
public function create($parameters)
{
if (isset($parameters->parameters)) {
$this->setDefaultParameters($parameters->parameters);
}
/** @var ConnectionWrapper $connection */
$connection = parent::create($parameters);

Expand Down
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ private function addClientsSection(ArrayNodeDefinition $rootNode)
->scalarNode('prefix')->defaultNull()->end()
->enumNode('replication')->values(array(true, false, 'sentinel'))->end()
->scalarNode('service')->defaultNull()->end()
->arrayNode('parameters')
->canBeUnset()
->children()
->scalarNode('database')->defaultNull()->end()
->scalarNode('password')->defaultNull()->end()
->booleanNode('logging')->defaultValue($this->debug)->end()
->end()
->end()
->end()
->end()
->end()
Expand Down
6 changes: 6 additions & 0 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ snc_redis:
options:
replication: sentinel
service: mymaster
parameters:
database: 1
password: pass
```

The `service` is the name of the set of Redis instances.
The optional parameters option can be used to set parameters like the
database number and password for the master/slave connections,
they don't apply for the connection to sentinal.
You can find more information about this on [Configuring Sentinel](https://redis.io/topics/sentinel#configuring-sentinel).

### Sessions ###
Expand Down
9 changes: 9 additions & 0 deletions Tests/DependencyInjection/SncRedisExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ public function testSentinelOption()
$masterParameters = $container->getDefinition((string) $parameters[0])->getArgument(0);
$this->assertEquals('sentinel', $masterParameters['replication']);
$this->assertEquals('mymaster', $masterParameters['service']);
$this->assertInternalType('array', $masterParameters['parameters']);
$this->assertEquals('1', $masterParameters['parameters']['database']);
$this->assertEquals('pass', $masterParameters['parameters']['password']);

$this->assertInternalType('array', $container->findTaggedServiceIds('snc_redis.client'));
$this->assertEquals(array('snc_redis.default' => array(array('alias' => 'default'))), $container->findTaggedServiceIds('snc_redis.client'));
Expand Down Expand Up @@ -408,6 +411,9 @@ private function getFullYamlConfig()
throw_errors: true
cluster: Snc\RedisBundle\Client\Predis\Connection\PredisCluster
replication: false
parameters:
database: 1
password: pass
session:
client: default
prefix: foo
Expand Down Expand Up @@ -522,6 +528,9 @@ private function getSentinelYamlConfig()
options:
replication: sentinel
service: mymaster
parameters:
database: 1
password: pass
EOF;
}

Expand Down

0 comments on commit a2ffea7

Please sign in to comment.