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