line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Katsubushi::Client; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
124159
|
use 5.008001; |
|
3
|
|
|
|
|
7
|
|
4
|
3
|
|
|
3
|
|
9
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
48
|
|
5
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
99
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.1"; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1538
|
use Cache::Memcached::Fast; |
|
3
|
|
|
|
|
6236
|
|
|
3
|
|
|
|
|
77
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
13
|
use Carp qw(croak); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
256
|
|
12
|
|
|
|
|
|
|
use Class::Tiny +{ |
13
|
0
|
|
|
|
|
|
servers => sub { ["127.0.0.1:11212"] }, |
14
|
|
|
|
|
|
|
_models => sub { |
15
|
0
|
|
|
|
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
return [ map { |
17
|
0
|
|
|
|
|
|
Cache::Memcached::Fast->new({ servers => [ $_ ] }); |
18
|
0
|
|
|
|
|
|
} @{$self->servers} ]; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
}, |
20
|
3
|
|
|
3
|
|
1227
|
}; |
|
3
|
|
|
|
|
6150
|
|
|
3
|
|
|
|
|
23
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if (scalar @{$self->servers} < 1) { |
|
0
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
die 'there are no servers.'; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub fetch { |
31
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $id = 0; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# retry at once for only main (the first of list) server |
36
|
0
|
|
|
|
|
|
for my $model ($self->_models->[0], @{$self->_models}) { |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$id = $model->get('id'); |
38
|
0
|
0
|
|
|
|
|
last if $id; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
unless ($id) { |
42
|
0
|
|
|
|
|
|
croak 'Failed to fetch new id'; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $id; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub fetch_multi { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my $n = shift; |
51
|
0
|
|
|
|
|
|
my @keys = ( 1 .. $n ); |
52
|
0
|
|
|
|
|
|
my $ids; |
53
|
|
|
|
|
|
|
# retry at once for only main (the first of list) server |
54
|
0
|
|
|
|
|
|
for my $model ($self->_models->[0], @{$self->_models}) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$ids = $model->get_multi(@keys); |
56
|
0
|
0
|
|
|
|
|
last if scalar(values %$ids) == $n; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (scalar values %$ids != $n) { |
60
|
0
|
|
|
|
|
|
croak "Failed to fetch new $n ids"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return map { $ids->{$_} } @keys; |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |