line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RedisScript; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
265683
|
use 5.026001; |
|
4
|
|
|
|
|
37
|
|
4
|
4
|
|
|
4
|
|
20
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
84
|
|
5
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
180
|
|
6
|
4
|
|
|
4
|
|
24
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1816
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @_needed_args_for_new = qw{ redis code }; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
15
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
## init args |
18
|
|
|
|
|
|
|
defined $args{ $_ } |
19
|
|
|
|
|
|
|
and $self->{ $_ } = $args{ $_ } |
20
|
0
|
|
0
|
|
|
|
for @_needed_args_for_new; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
## args validation |
23
|
|
|
|
|
|
|
croak( q{missing redis args or invalid redis object} ) |
24
|
|
|
|
|
|
|
unless( defined( $self->{redis} ) |
25
|
|
|
|
|
|
|
and ( UNIVERSAL::isa( $self->{redis}, q{Redis} ) |
26
|
0
|
0
|
0
|
|
|
|
or $self->{redis}->can( q{script_load} ) |
|
|
|
0
|
|
|
|
|
27
|
|
|
|
|
|
|
) |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->__init_code(); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub __init_code { |
36
|
0
|
|
|
0
|
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
## any cached hash?? |
39
|
0
|
0
|
|
|
|
|
if( ! exists $self->{_sha_cache} ) { |
40
|
|
|
|
|
|
|
## need to load script |
41
|
0
|
|
|
|
|
|
$self->__load_script(); |
42
|
0
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
## check if script is loaded |
46
|
0
|
0
|
|
|
|
|
if( $self->{ redis }->script_exists( $self->{_sha_cache} ) ne 1 ) { |
47
|
0
|
|
|
|
|
|
$self->__load_script(); |
48
|
0
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub __load_script { |
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $sha = $self->{redis}->script_load( $self->{ code } ); |
57
|
0
|
|
|
|
|
|
$self->{_sha_cache} = $sha; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub runit { |
63
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my %args = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->__init_code(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
croak( q{need two array ref as args (keys and args)} ) |
69
|
|
|
|
|
|
|
unless( ( defined( $args{keys} ) |
70
|
|
|
|
|
|
|
and ( ref( $args{keys} ) eq q{ARRAY} ) |
71
|
|
|
|
|
|
|
) |
72
|
|
|
|
|
|
|
and ( defined( $args{args} ) |
73
|
0
|
0
|
0
|
|
|
|
and ( ref( $args{args} ) eq q{ARRAY} ) ) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return $self->{redis}->evalsha( $self->{_sha_cache}, |
77
|
0
|
|
|
|
|
|
scalar @{ $args{keys} }, |
78
|
0
|
|
|
|
|
|
@{ $args{keys} }, |
79
|
0
|
|
|
|
|
|
@{ $args{args} }, |
|
0
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |