Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): selecting database before auth caused error #85

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
/**
* A default host to connect to
*/
const DEFAULT_HOST = 'localhost';

Check warning on line 29 in lib/Redis.php

View workflow job for this annotation

GitHub Actions / PHPCS

Visibility must be declared on all constants if your project supports PHP 7.1 or later

/**
* The default Redis port
*/
const DEFAULT_PORT = 6379;

Check warning on line 34 in lib/Redis.php

View workflow job for this annotation

GitHub Actions / PHPCS

Visibility must be declared on all constants if your project supports PHP 7.1 or later

/**
* The default Redis Database number
*/
const DEFAULT_DATABASE = 0;

Check warning on line 39 in lib/Redis.php

View workflow job for this annotation

GitHub Actions / PHPCS

Visibility must be declared on all constants if your project supports PHP 7.1 or later

/**
* Connection driver
Expand Down Expand Up @@ -125,7 +125,7 @@
* DSN-supplied value will be used instead and this parameter is ignored.
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
*/
public function __construct($server, $database = null, $client = null)
public function __construct($server, $database = null, $client = null, $auth = null)
{
try {
if (is_object($client)) {
Expand All @@ -146,7 +146,7 @@
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
$this->driver->setMaxConnectRetries($maxRetries);
if ($password) {
$this->driver->auth($password);
$auth = $password;
}

// If we have found a database in our DSN, use it instead of the `$database`
Expand All @@ -156,6 +156,10 @@
}
}

if ($auth !== null) {
$this->driver->auth($auth);
}

if ($database !== null) {
$this->driver->select($database);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/
class Resque
{
const VERSION = '1.2';

Check warning on line 17 in lib/Resque.php

View workflow job for this annotation

GitHub Actions / PHPCS

Visibility must be declared on all constants if your project supports PHP 7.1 or later

const DEFAULT_INTERVAL = 5;

Check warning on line 19 in lib/Resque.php

View workflow job for this annotation

GitHub Actions / PHPCS

Visibility must be declared on all constants if your project supports PHP 7.1 or later

/**
* @var Redis Instance of Resque\Redis that talks to redis.
Expand Down Expand Up @@ -72,7 +72,7 @@
if (is_callable(self::$redisServer)) {
self::$redis = call_user_func(self::$redisServer, self::$redisDatabase);
} else {
self::$redis = new Redis(self::$redisServer, self::$redisDatabase);
self::$redis = new Redis(self::$redisServer, self::$redisDatabase, null, self::$auth);
}

if (!empty(self::$auth)) {
Expand Down
Loading