Readd Credis

This commit is contained in:
Daniel Mason 2018-05-30 19:05:13 +12:00
parent 493d6dc6d8
commit bd0a0c2dc8
5 changed files with 1599 additions and 26 deletions

View File

@ -1,3 +1,6 @@
## 1.4.2 (2018-05-30)
- Reimplemented credis due to issues with Redis: Connection Closed.
## 1.4.1 (2018-05-29)
- Updated travis builds to run on PHP 7.0, 7.1 and 7.2.
- Added ability to specify multiple log levels. [DEBUG/INFO/NOTICE/WARNING/ERROR/CRITICAL/ALERT/EMERGENCY]
@ -7,7 +10,7 @@
## 1.4 (2018-05-25)
- Forked from chrisboulton/php-resque.
- Replaced credis (rather unmaintained) in favour of phpredis.
- Replaced credis in favour of phpredis.
- Reformatted codebase to be PSR2 compliant.

View File

@ -1,6 +1,6 @@
{
"name": "idanoo/php-resque",
"version": "1.4.1",
"version": "1.4.2",
"type": "library",
"description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby. Originally forked from chrisboulton/php-resque.",
"keywords": ["job", "background", "redis", "resque"],
@ -13,10 +13,11 @@
}
],
"require": {
"php": ">=7.0.0",
"php": "^7.0",
"ext-pcntl": "*",
"ext-redis": "*",
"psr/log": "~1.0"
"psr/log": "~1.0",
"colinmollenhour/credis": "^1.10"
},
"suggest": {
"ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker."

1570
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,12 @@
class Resque_Redis
{
/**
* Redis Client
* @var Credis_Client
*/
private $driver;
/**
* Redis namespace
* @var string
@ -110,41 +116,36 @@ class Resque_Redis
* @param string|array $server A DSN or array
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
* 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
* @param object $client Optional Credis_Client instance instantiated by you
* @throws Resque_RedisException
*/
public function __construct($server, $database = null, $client = null)
{
try {
if (is_object($client)) {
$this->redisConnection = $client;
$this->driver = $client;
} else {
/** @noinspection PhpUnusedLocalVariableInspection */
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
// $user is not used, only $password
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
$this->redisConnection = new Redis();
if (!$this->redisConnection->connect($host, $port, $timeout)) {
throw new RedisException("Connection Failed to Redis!");
};
$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->redisConnection->auth($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 ($database) {
$this->redisConnection->select($database);
}
if ($database !== null) {
$this->driver->select($database);
}
} catch (RedisException $e) {
} catch (Exception $e) {
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
}
}
@ -245,8 +246,8 @@ class Resque_Redis
}
}
try {
return call_user_func_array([$this->redisConnection, $name], $args);
} catch (Exception $e) {
return $this->driver->__call($name, $args);
} catch (CredisException $e) {
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
}
}

View File

@ -20,10 +20,8 @@ class Resque_Tests_TestCase extends PHPUnit\Framework\TestCase
public function setUp()
{
// Setup redis connection on DB 9 for testing.
$this->redis = new Redis();
$this->redis->connect('localhost');
// Setup redis connection for testing.
$this->redis = new Credis_Client('localhost', '6379');
Resque::setBackend('localhost');
$this->redis->flushAll();
}