Skip to content

Commit

Permalink
Merge 'varvar/master' into old-pulls
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed Dec 11, 2018
2 parents bb25f4b + 5290fde commit f86211b
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions lib/Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public static function pop($queue)
public static function dequeue($queue, $items = Array())
{
if(count($items) > 0) {
return self::removeItems($queue, $items);
return self::removeItems($queue, $items);
} else {
return self::removeList($queue);
return self::removeList($queue);
}
}

Expand Down Expand Up @@ -264,6 +264,20 @@ public static function queues()
return $queues;
}

/**
* Retrieve all the items of a queue with Redis
*
* @return array Array of items.
*/
public static function items($queue, $start = 0, $stop = -1)
{
$list = self::redis()->lrange('queue:' . $queue, $start, $stop);
if(!is_array($list)) {
$list = array();
}
return $list;
}

/**
* Remove Items from the queue
* Safely moving each item to a temporary queue before processing it
Expand Down Expand Up @@ -318,7 +332,7 @@ private static function removeItems($queue, $items = Array())

/**
* matching item
* item can be ['class'] or ['class' => 'id'] or ['class' => {:foo => 1, :bar => 2}]
* item can be ['class'] or ['class' => 'id'] or ['class' => {'foo' => 1, 'bar' => 2}]
* @private
*
* @params string $string redis result in json
Expand All @@ -331,24 +345,24 @@ private static function matchItem($string, $items)
$decoded = json_decode($string, true);

foreach($items as $key => $val) {
# class name only ex: item[0] = ['class']
if (is_numeric($key)) {
if($decoded['class'] == $val) {
return true;
}
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
} elseif (is_array($val)) {
$decodedArgs = (array)$decoded['args'][0];
if ($decoded['class'] == $key &&
count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) {
return true;
# class name only ex: item[0] = ['class']
if (is_numeric($key)) {
if($decoded['class'] == $val) {
return true;
}
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
} elseif (is_array($val)) {
$decodedArgs = (array)$decoded['args'][0];
if ($decoded['class'] == $key &&
count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) {
return true;
}
# class name with ID, example: item[0] = ['class' => 'id']
} else {
if ($decoded['class'] == $key && $decoded['id'] == $val) {
return true;
}
}
# class name with ID, example: item[0] = ['class' => 'id']
} else {
if ($decoded['class'] == $key && $decoded['id'] == $val) {
return true;
}
}
}
return false;
}
Expand Down

0 comments on commit f86211b

Please sign in to comment.