Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a3e2be

Browse files
committed
added auth support to redis.
1 parent bb94270 commit 1a3e2be

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/Illuminate/Redis/Database.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class Database {
2323
*/
2424
protected $database;
2525

26+
/**
27+
* The password value.
28+
*
29+
* @var string
30+
*/
31+
protected $password;
32+
2633
/**
2734
* The Redis connection handler.
2835
*
@@ -36,13 +43,15 @@ class Database {
3643
* @param string $host
3744
* @param int $port
3845
* @param int $database
46+
* @param string $password
3947
* @return void
4048
*/
41-
public function __construct($host, $port, $database = 0)
49+
public function __construct($host, $port, $database = 0, $password = null)
4250
{
4351
$this->host = $host;
4452
$this->port = $port;
4553
$this->database = $database;
54+
$this->password = $password;
4655
}
4756

4857
/**
@@ -56,6 +65,11 @@ public function connect()
5665

5766
$this->connection = $this->openSocket();
5867

68+
if ( ! is_null($this->password))
69+
{
70+
$this->command('auth', array($this->password));
71+
}
72+
5973
$this->command('select', array($this->database));
6074
}
6175

src/Illuminate/Redis/RedisManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ protected function createConnection($name)
5555
{
5656
$config = $this->getConfig($name);
5757

58-
$connection = new Database($config['host'], $config['port'], $config['database']);
58+
// Redis may optionally have a password. So, we will attempt to extract out
59+
// the password from the configuration. But one is not required so we'll
60+
// just use array_get to return null if one hasn't been set in config.
61+
$password = array_get($config, 'password');
62+
63+
$connection = new Database($config['host'], $config['port'], $config['database'], $password);
5964

6065
$connection->connect();
6166

0 commit comments

Comments
 (0)