line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Qless::Lua; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Qless::Lua |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
9
|
1
|
|
|
1
|
|
768
|
use File::ShareDir qw(); |
|
1
|
|
|
|
|
6604
|
|
|
1
|
|
|
|
|
63
|
|
10
|
1
|
|
|
1
|
|
9
|
use overload '&{}' => sub { my $self = shift; sub { $self->call(@_) }; }, fallback => 1; |
|
1
|
|
|
0
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
14
|
0
|
|
|
|
|
|
my ($name, $r) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
17
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$self->{'name'} = $name; |
20
|
0
|
|
|
|
|
|
$self->{'redis'} = $r; |
21
|
0
|
|
|
|
|
|
$self->{'sha'} = undef; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub reload { |
27
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $filename = File::ShareDir::dist_file('Qless', $self->{'name'}.'.lua'); |
30
|
0
|
0
|
|
|
|
|
open my $fh, '<', $filename or die $!; |
31
|
0
|
|
|
|
|
|
my $content = do { local $/; <$fh> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
close $fh; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self->{'sha'} = $self->{'redis'}->script('load', $content); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub call { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $keys, @args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
$self->reload if !$self->{'sha'}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
|
$keys ||= []; |
43
|
0
|
|
|
|
|
|
my $keys_count = scalar @{ $keys }; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $rv = eval { |
46
|
0
|
0
|
|
|
|
|
$self->{'redis'}->evalsha($self->{'sha'}, $keys_count, $keys_count ? @{ $keys } : (), @args); |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($@) { |
50
|
0
|
|
|
|
|
|
$self->reload; |
51
|
0
|
0
|
|
|
|
|
$rv = $self->{'redis'}->evalsha($self->{'sha'}, $keys_count, $keys_count ? @{ $keys } : (), @args); |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $rv; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |