Skip to content

Commit

Permalink
Merge pull request #12 from timnolte/feature/auth
Browse files Browse the repository at this point in the history
Adds Redis authentication support
  • Loading branch information
vetruvet committed Jun 9, 2016
2 parents 1dc73e0 + bfe6939 commit 8f814ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ All options are optional, you can specify an empty array to get the default conn
'default' => array(
'host' => '127.0.0.1', // default: '127.0.0.1'
'port' => 6379, // default: 6379
'password' => password // default: null
'prefix' => 'myapp:', // default: ''
'database' => 7, // default: 0
'timeout' => 0.5, // default: 0 (no timeout)
Expand All @@ -84,4 +85,4 @@ The only option that is not self-explanatory is the `serializer` option. The val
[laravel]:http://laravel.com/
[predis]:https://github.com/nrk/predis
[phpredis]:https://github.com/nicolasff/phpredis
[1]:https://github.com/nicolasff/phpredis#installingconfiguring
[1]:https://github.com/nicolasff/phpredis#installingconfiguring
14 changes: 10 additions & 4 deletions src/Vetruvet/PhpRedis/Database.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

namespace Vetruvet\PhpRedis;

Expand Down Expand Up @@ -41,6 +41,7 @@ protected function createAggregateClient(array $servers, array $options = []) {
}

$cluster[$host.':'.$port] = array(
'password' => empty($server['password']) ? '' : $server['password'],
'prefix' => empty($server['prefix']) ? '' : $server['prefix'],
'database' => empty($server['database']) ? 0 : $server['database'],
'serializer' => $serializer,
Expand All @@ -61,9 +62,10 @@ protected function createAggregateClient(array $servers, array $options = []) {

foreach ($cluster as $host => $options) {
$redis = $ra->_instance($host);
$redis->setOption(Redis::OPT_PREFIX, $options['prefix']);
$redis->setOption(Redis::OPT_SERIALIZER, $options['serializer']);
$redis->select($options['database']);
$redis->setOption(Redis::OPT_PREFIX, $options['prefix']);
$redis->setOption(Redis::OPT_SERIALIZER, $options['serializer']);
$redis->auth($options['password']);
$redis->select($options['database']);
}

return array('default' => $ra);
Expand Down Expand Up @@ -97,6 +99,10 @@ protected function createSingleClients(array $servers, array $options = []) {
$redis->setOption(Redis::OPT_PREFIX, $server['prefix']);
}

if (!empty($server['password'])) {
$redis->auth($server['password']);
}

if (!empty($server['database'])) {
$redis->select($server['database']);
}
Expand Down

0 comments on commit 8f814ef

Please sign in to comment.