Resque\Helpers\Stats::incr PHP Method

incr() public static method

Increment the value of the specified statistic by a certain amount (default is 1)
public static incr ( string $stat, integer $by = 1, string $key = Stats::DEFAULT_KEY ) : boolean
$stat string The name of the statistic to increment
$by integer The amount to increment the statistic by
$key string The stat key to use
return boolean True if successful, false if not.
    public static function incr($stat, $by = 1, $key = Stats::DEFAULT_KEY)
    {
        return (bool) Redis::instance()->hincrby($key, $stat, $by);
    }

Usage Example

Example #1
0
 /**
  * Mark the current job as having failed
  * 
  * @param \Exception $e
  */
 public function fail(\Exception $e)
 {
     $this->stopped();
     $this->setStatus(Job::STATUS_FAILED, $e);
     // For the failed jobs we store a lot more data for debugging
     $packet = $this->getPacket();
     $failed_payload = array_merge(json_decode($this->payload, true), array('worker' => $packet['worker'], 'started' => $packet['started'], 'finished' => $packet['finished'], 'output' => $packet['output'], 'exception' => (array) json_decode($packet['exception'], true)));
     $this->redis->zadd(Queue::redisKey($this->queue, 'failed'), time(), json_encode($failed_payload));
     Stats::incr('failed', 1);
     Stats::incr('failed', 1, Queue::redisKey($this->queue, 'stats'));
     Event::fire(Event::JOB_FAILURE, array($this, $e));
 }