line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Resque::Stat; |
2
|
|
|
|
|
|
|
# ABSTRACT: The stat subsystem. Used to keep track of integer counts. |
3
|
|
|
|
|
|
|
$Resque::Stat::VERSION = '0.40'; |
4
|
9
|
|
|
9
|
|
68
|
use Moose; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
77
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has resque => ( |
7
|
|
|
|
|
|
|
is => 'ro', |
8
|
|
|
|
|
|
|
required => 1, |
9
|
|
|
|
|
|
|
handles => [qw/ redis key /] |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get { |
13
|
0
|
|
|
0
|
1
|
|
my ($self, $stat) = @_; |
14
|
0
|
0
|
|
|
|
|
$self->redis->get( $self->key( stat => $stat ) ) || 0; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub incr { |
18
|
0
|
|
|
0
|
1
|
|
my ( $self, $stat, $by ) = @_; |
19
|
0
|
|
0
|
|
|
|
$by ||= 1; |
20
|
0
|
|
|
|
|
|
$self->redis->incrby( $self->key( stat => $stat ), $by ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub decr { |
24
|
0
|
|
|
0
|
1
|
|
my ( $self, $stat, $by ) = @_; |
25
|
0
|
|
0
|
|
|
|
$by ||= 1; |
26
|
0
|
|
|
|
|
|
$self->redis->decrby( $self->key( stat => $stat ), $by ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub clear { |
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $stat ) = @_; |
31
|
0
|
|
|
|
|
|
$self->redis->del( $self->key( stat => $stat ) ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=encoding UTF-8 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Resque::Stat - The stat subsystem. Used to keep track of integer counts. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
version 0.40 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 resque |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 get |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns the int value of a stat, given a string stat name. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $value = $resque_stat->get( 'stat_name' ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 incr |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
For a string stat name, increments the stat by one. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Can optionally accept a second int parameter. The stat is then |
67
|
|
|
|
|
|
|
incremented by that amount. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $value = $resque_stat->incr( 'stat_name', $optional_inc_by ); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 decr |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
For a string stat name, decrements the stat by one. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Can optionally accept a second int parameter. The stat is then |
76
|
|
|
|
|
|
|
decremented by that amount. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $value = $resque_stat->decr( 'stat_name', $optional_dec_by ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 clear |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Removes a stat from Redis, effectively setting it to 0. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$resque_stat->clear( 'stat_name' ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Diego Kuperman <diego@freekeylabs.com> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Diego Kuperman. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
95
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |