Skip to content

Commit 5bbe8f2

Browse files
jasverixdanhunsaker
authored andcommitted
fix(auth): selecting database before auth caused error
1 parent b3131f2 commit 5bbe8f2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/Redis.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static function prefix($namespace)
125125
* DSN-supplied value will be used instead and this parameter is ignored.
126126
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
127127
*/
128-
public function __construct($server, $database = null, $client = null)
128+
public function __construct($server, $database = null, $client = null, $auth = null)
129129
{
130130
try {
131131
if (is_object($client)) {
@@ -146,7 +146,7 @@ public function __construct($server, $database = null, $client = null)
146146
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
147147
$this->driver->setMaxConnectRetries($maxRetries);
148148
if ($password) {
149-
$this->driver->auth($password);
149+
$auth = $password;
150150
}
151151

152152
// If we have found a database in our DSN, use it instead of the `$database`
@@ -156,6 +156,10 @@ public function __construct($server, $database = null, $client = null)
156156
}
157157
}
158158

159+
if ($auth !== null) {
160+
$this->driver->auth($auth);
161+
}
162+
159163
if ($database !== null) {
160164
$this->driver->select($database);
161165
}

lib/Resque.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function redis()
7272
if (is_callable(self::$redisServer)) {
7373
self::$redis = call_user_func(self::$redisServer, self::$redisDatabase);
7474
} else {
75-
self::$redis = new Redis(self::$redisServer, self::$redisDatabase);
75+
self::$redis = new Redis(self::$redisServer, self::$redisDatabase, null, self::$auth);
7676
}
7777

7878
if (!empty(self::$auth)) {

0 commit comments

Comments
 (0)