line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# client::memcached Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Client::Memcached; |
7
|
1
|
|
|
1
|
|
689
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
553
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
servers => [ qw(server|server_list) ], |
20
|
|
|
|
|
|
|
_c => [ qw(INTERNAL) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
attributes_default => { |
23
|
|
|
|
|
|
|
servers => [ qw(127.0.0.1:11211) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
commands => { |
26
|
|
|
|
|
|
|
open => [ qw(server|server_list|OPTIONAL) ], |
27
|
|
|
|
|
|
|
close => [ ], |
28
|
|
|
|
|
|
|
write => [ qw(key value) ], |
29
|
|
|
|
|
|
|
read => [ qw(key) ], |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
require_modules => { |
32
|
|
|
|
|
|
|
'Cache::Memcached' => [ ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub brik_init { |
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
$self->open or return 0; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self->SUPER::brik_init; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# run client::memcached open "[qw(127.0.0.1:11211)]" |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
sub open { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my ($servers) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
$servers ||= $self->servers; |
53
|
0
|
0
|
|
|
|
|
$self->brik_help_set_undef_arg('servers', $servers) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $c = Cache::Memcached->new({ |
56
|
|
|
|
|
|
|
servers => $servers, |
57
|
|
|
|
|
|
|
}); |
58
|
0
|
0
|
|
|
|
|
if (!defined($c)) { |
59
|
0
|
|
|
|
|
|
return $self->log->error("open: memcached failed: $!"); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
$c->enable_compress(0); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->_c($c); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub close { |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $c = $self->_c; |
70
|
0
|
0
|
|
|
|
|
if (defined($c)) { |
71
|
0
|
|
|
|
|
|
$c->disconnect_all; |
72
|
0
|
|
|
|
|
|
$self->_c(undef); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub write { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my ($k, $v) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $c = $self->_c; |
83
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('open', $c) or return; |
84
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('write', $k) or return; |
85
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('write', $v) or return; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $c->set($k, $v); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub read { |
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my ($k) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $c = $self->_c; |
95
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('open', $c) or return; |
96
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('read', $k) or return; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $c->get($k); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |