1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Resque; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Resque statistic management (jobs processed, failed, etc) |
7
|
|
|
* |
8
|
|
|
* @package Resque/Stat |
9
|
|
|
* @author Chris Boulton <[email protected]> |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
11
|
|
|
*/ |
12
|
|
|
class Stat |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Get the value of the supplied statistic counter for the specified statistic. |
16
|
|
|
* |
17
|
|
|
* @param string $stat The name of the statistic to get the stats for. |
18
|
|
|
* @return mixed Value of the statistic. |
19
|
|
|
*/ |
20
|
|
|
public static function get($stat) |
21
|
|
|
{ |
22
|
|
|
return (int)Resque::redis()->get('stat:' . $stat); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Increment the value of the specified statistic by a certain amount (default is 1) |
27
|
|
|
* |
28
|
|
|
* @param string $stat The name of the statistic to increment. |
29
|
|
|
* @param int $by The amount to increment the statistic by. |
30
|
|
|
* @return boolean True if successful, false if not. |
31
|
|
|
*/ |
32
|
|
|
public static function incr($stat, $by = 1) |
33
|
|
|
{ |
34
|
|
|
return (bool)Resque::redis()->incrby('stat:' . $stat, $by); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Decrement the value of the specified statistic by a certain amount (default is 1) |
39
|
|
|
* |
40
|
|
|
* @param string $stat The name of the statistic to decrement. |
41
|
|
|
* @param int $by The amount to decrement the statistic by. |
42
|
|
|
* @return boolean True if successful, false if not. |
43
|
|
|
*/ |
44
|
|
|
public static function decr($stat, $by = 1) |
45
|
|
|
{ |
46
|
|
|
return (bool)Resque::redis()->decrby('stat:' . $stat, $by); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Delete a statistic with the given name. |
51
|
|
|
* |
52
|
|
|
* @param string $stat The name of the statistic to delete. |
53
|
|
|
* @return boolean True if successful, false if not. |
54
|
|
|
*/ |
55
|
|
|
public static function clear($stat) |
56
|
|
|
{ |
57
|
|
|
return (bool)Resque::redis()->del('stat:' . $stat); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|