mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 00:11:53 +00:00
commit
45c49cf002
@ -16,6 +16,11 @@ if(!class_exists('Redisent')) {
|
||||
*/
|
||||
class Resque_Redis extends Redisent
|
||||
{
|
||||
/**
|
||||
* Redis namespace
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultNamespace = 'resque:';
|
||||
/**
|
||||
* @var array List of all commands in Redis that supply a key as their
|
||||
* first argument. Used to prefix keys with the Resque namespace.
|
||||
@ -76,10 +81,22 @@ class Resque_Redis extends Redisent
|
||||
// msetnx
|
||||
// mset
|
||||
// renamenx
|
||||
|
||||
|
||||
/**
|
||||
* Set Redis namespace (prefix) default: resque
|
||||
* @param string $namespace
|
||||
*/
|
||||
public static function prefix($namespace)
|
||||
{
|
||||
if (strpos($namespace, ':') === false) {
|
||||
$namespace .= ':';
|
||||
}
|
||||
self::$defaultNamespace = $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to handle all function requests and prefix key based
|
||||
* operations with the 'resque:' key prefix.
|
||||
* operations with the {self::$defaultNamespace} key prefix.
|
||||
*
|
||||
* @param string $name The name of the method called.
|
||||
* @param array $args Array of supplied arguments to the method.
|
||||
@ -88,7 +105,7 @@ class Resque_Redis extends Redisent
|
||||
public function __call($name, $args) {
|
||||
$args = func_get_args();
|
||||
if(in_array($name, $this->keyCommands)) {
|
||||
$args[1][0] = 'resque:' . $args[1][0];
|
||||
$args[1][0] = self::$defaultNamespace . $args[1][0];
|
||||
}
|
||||
try {
|
||||
return parent::__call($name, $args[1]);
|
||||
|
@ -16,6 +16,11 @@ if(!class_exists('RedisentCluster')) {
|
||||
*/
|
||||
class Resque_RedisCluster extends RedisentCluster
|
||||
{
|
||||
/**
|
||||
* Redis namespace
|
||||
* @var string
|
||||
*/
|
||||
private static $defaultNamespace = 'resque:';
|
||||
/**
|
||||
* @var array List of all commands in Redis that supply a key as their
|
||||
* first argument. Used to prefix keys with the Resque namespace.
|
||||
@ -76,10 +81,22 @@ class Resque_RedisCluster extends RedisentCluster
|
||||
// msetnx
|
||||
// mset
|
||||
// renamenx
|
||||
|
||||
/**
|
||||
* Set Redis namespace (prefix) default: resque
|
||||
* @param string $namespace
|
||||
*/
|
||||
public static function prefix($namespace)
|
||||
{
|
||||
if (strpos($namespace, ':') === false) {
|
||||
$namespace .= ':';
|
||||
}
|
||||
self::$defaultNamespace = $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to handle all function requests and prefix key based
|
||||
* operations with the 'resque:' key prefix.
|
||||
* operations with the '{self::$defaultNamespace}' key prefix.
|
||||
*
|
||||
* @param string $name The name of the method called.
|
||||
* @param array $args Array of supplied arguments to the method.
|
||||
@ -88,7 +105,7 @@ class Resque_RedisCluster extends RedisentCluster
|
||||
public function __call($name, $args) {
|
||||
$args = func_get_args();
|
||||
if(in_array($name, $this->keyCommands)) {
|
||||
$args[1][0] = 'resque:' . $args[1][0];
|
||||
$args[1][0] = self::$defaultNamespace . $args[1][0];
|
||||
}
|
||||
try {
|
||||
return parent::__call($name, $args[1]);
|
||||
|
@ -100,6 +100,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
$this->assertEquals($job->payload['args'], $newJob->getArguments());
|
||||
}
|
||||
|
||||
|
||||
public function testFailedJobExceptionsAreCaught()
|
||||
{
|
||||
$payload = array(
|
||||
@ -166,4 +167,18 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
$this->assertTrue(Test_Job_With_TearDown::$called);
|
||||
}
|
||||
|
||||
public function testJobWithNamespace()
|
||||
{
|
||||
Resque_Redis::prefix('php');
|
||||
$queue = 'jobs';
|
||||
$payload = array('another_value');
|
||||
Resque::enqueue($queue, 'Test_Job_With_TearDown', $payload);
|
||||
|
||||
$this->assertEquals(Resque::queues(), array('jobs'));
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
|
||||
Resque_Redis::prefix('resque');
|
||||
$this->assertEquals(Resque::size($queue), 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user