Skip to content

Commit c38c3e7

Browse files
jasverixdanhunsaker
authored andcommitted
fix(auth): selecting database before auth caused error
1 parent 7e03f6e commit c38c3e7

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
@@ -151,7 +151,7 @@ public static function prefix($namespace)
151151
* DSN-supplied value will be used instead and this parameter is ignored.
152152
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
153153
*/
154-
public function __construct($server, $database = null, $client = null)
154+
public function __construct($server, $database = null, $client = null, $auth = null)
155155
{
156156
try {
157157
if (is_object($client)) {
@@ -172,7 +172,7 @@ public function __construct($server, $database = null, $client = null)
172172
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
173173
$this->driver->setMaxConnectRetries($maxRetries);
174174
if ($password) {
175-
$this->driver->auth($password);
175+
$auth = $password;
176176
}
177177

178178
// If we have found a database in our DSN, use it instead of the `$database`
@@ -182,6 +182,10 @@ public function __construct($server, $database = null, $client = null)
182182
}
183183
}
184184

185+
if ($auth !== null) {
186+
$this->driver->auth($auth);
187+
}
188+
185189
if ($database !== null) {
186190
$this->driver->select($database);
187191
}

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)