2010-04-18 13:58:43 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Resque statistic management (jobs processed, failed, etc)
|
|
|
|
*
|
|
|
|
* @package Resque/Stat
|
2012-10-13 06:55:41 +00:00
|
|
|
* @author Chris Boulton <chris@bigcommerce.com>
|
2010-04-18 13:58:43 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*/
|
|
|
|
class Resque_Stat
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get the value of the supplied statistic counter for the specified statistic.
|
|
|
|
*
|
|
|
|
* @param string $stat The name of the statistic to get the stats for.
|
|
|
|
* @return mixed Value of the statistic.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function get($stat)
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
return (int)Resque::redis()->get('stat:' . $stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment the value of the specified statistic by a certain amount (default is 1)
|
|
|
|
*
|
|
|
|
* @param string $stat The name of the statistic to increment.
|
|
|
|
* @param int $by The amount to increment the statistic by.
|
|
|
|
* @return boolean True if successful, false if not.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function incr($stat, $by = 1)
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
return (bool)Resque::redis()->incrby('stat:' . $stat, $by);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrement the value of the specified statistic by a certain amount (default is 1)
|
|
|
|
*
|
|
|
|
* @param string $stat The name of the statistic to decrement.
|
|
|
|
* @param int $by The amount to decrement the statistic by.
|
|
|
|
* @return boolean True if successful, false if not.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function decr($stat, $by = 1)
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
return (bool)Resque::redis()->decrby('stat:' . $stat, $by);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a statistic with the given name.
|
|
|
|
*
|
|
|
|
* @param string $stat The name of the statistic to delete.
|
|
|
|
* @return boolean True if successful, false if not.
|
|
|
|
*/
|
2010-11-18 06:01:10 +00:00
|
|
|
public static function clear($stat)
|
2010-04-18 13:58:43 +00:00
|
|
|
{
|
|
|
|
return (bool)Resque::redis()->del('stat:' . $stat);
|
|
|
|
}
|
|
|
|
}
|