line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Hiredis; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
79915
|
$AnyEvent::Hiredis::VERSION = '0.05'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: AnyEvent hiredis API |
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
360
|
use namespace::autoclean; |
|
1
|
|
|
|
|
11726
|
|
|
1
|
|
|
|
|
4
|
|
9
|
1
|
|
|
1
|
|
203
|
use Hiredis::Async; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use AnyEvent; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my ($class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $self = bless {}, $class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$self->{host} = $args{host} || '127.0.0.1'; |
18
|
|
|
|
|
|
|
$self->{port} = $args{port} || 6379; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->{redis} = $self->_connect; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _connect { |
26
|
|
|
|
|
|
|
my ($self) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $redis = Hiredis::Async->new( |
29
|
|
|
|
|
|
|
host => $self->{host}, |
30
|
|
|
|
|
|
|
port => $self->{port}, |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
addRead => sub { $self->_add_read_cb(@_) }, |
33
|
|
|
|
|
|
|
delRead => sub { $self->_del_read_cb(@_) }, |
34
|
|
|
|
|
|
|
addWrite => sub { $self->_add_write_cb(@_) }, |
35
|
|
|
|
|
|
|
delWrite => sub { $self->_del_write_cb(@_) }, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $redis; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _add_read_cb { |
42
|
|
|
|
|
|
|
my ($self, $fd) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return if defined $self->{reader}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$self->{reader} = AnyEvent->io( fh => $fd, poll => 'r', cb => sub { |
47
|
|
|
|
|
|
|
$self->{redis}->HandleRead; |
48
|
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _del_read_cb { |
54
|
|
|
|
|
|
|
my ($self, $fd) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->{reader} = undef; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _add_write_cb { |
62
|
|
|
|
|
|
|
my ($self, $fd) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return if defined $self->{writer}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->{writer} = AnyEvent->io( fh => $fd, poll => 'w', cb => sub { |
67
|
|
|
|
|
|
|
$self->{redis}->HandleWrite; |
68
|
|
|
|
|
|
|
}); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _del_write_cb { |
74
|
|
|
|
|
|
|
my ($self, $fd) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$self->{writer} = undef; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub command { |
82
|
|
|
|
|
|
|
my ($self, $cmd, $cb) = @_; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$self->{redis}->Command($cmd, $cb); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub DESTROY { |
90
|
|
|
|
|
|
|
my ($self) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->{writer} = undef; |
93
|
|
|
|
|
|
|
$self->{reader} = undef; |
94
|
|
|
|
|
|
|
$self->{redis} = undef; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |