mirror of
https://github.com/idanoo/php-resque
synced 2025-07-01 13:42:22 +00:00
throw Resque_RedisException whenever an errror connecting/talking to redis occurs
This commit is contained in:
parent
ee9f133bf9
commit
81cb92b964
4 changed files with 49 additions and 27 deletions
|
@ -111,34 +111,38 @@ class Resque_Redis
|
|||
*/
|
||||
public function __construct($server, $database = null)
|
||||
{
|
||||
if (is_array($server)) {
|
||||
$this->driver = new Credis_Cluster($server);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
if (is_array($server)) {
|
||||
$this->driver = new Credis_Cluster($server);
|
||||
}
|
||||
else {
|
||||
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
||||
// $user is not used, only $password
|
||||
|
||||
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
||||
// $user is not used, only $password
|
||||
// Look for known Credis_Client options
|
||||
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
||||
$persistent = isset($options['persistent']) ? $options['persistent'] : '';
|
||||
$maxRetries = isset($options['max_connect_retries']) ? $options['max_connect_retries'] : 0;
|
||||
|
||||
// Look for known Credis_Client options
|
||||
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
||||
$persistent = isset($options['persistent']) ? $options['persistent'] : '';
|
||||
$maxRetries = isset($options['max_connect_retries']) ? $options['max_connect_retries'] : 0;
|
||||
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
|
||||
$this->driver->setMaxConnectRetries($maxRetries);
|
||||
if ($password){
|
||||
$this->driver->auth($password);
|
||||
}
|
||||
|
||||
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
|
||||
$this->driver->setMaxConnectRetries($maxRetries);
|
||||
if ($password){
|
||||
$this->driver->auth($password);
|
||||
// If we have found a database in our DSN, use it instead of the `$database`
|
||||
// value passed into the constructor.
|
||||
if ($dsnDatabase !== false) {
|
||||
$database = $dsnDatabase;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have found a database in our DSN, use it instead of the `$database`
|
||||
// value passed into the constructor.
|
||||
if ($dsnDatabase !== false) {
|
||||
$database = $dsnDatabase;
|
||||
if ($database !== null) {
|
||||
$this->driver->select($database);
|
||||
}
|
||||
}
|
||||
|
||||
if ($database !== null) {
|
||||
$this->driver->select($database);
|
||||
catch(CredisException $e) {
|
||||
throw new Resque_RedisException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,7 +245,7 @@ class Resque_Redis
|
|||
return $this->driver->__call($name, $args);
|
||||
}
|
||||
catch (CredisException $e) {
|
||||
return false;
|
||||
throw new Resque_RedisException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue