line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Connection::Redis; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1080
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: a mtpolicy connection for redis databases |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Mail::MtPolicyd::Connection'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4761
|
use Redis; |
|
1
|
|
|
|
|
9444
|
|
|
1
|
|
|
|
|
162
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'server' => ( is => 'ro', isa => 'Str', default => '127.0.0.1:6379' ); |
14
|
|
|
|
|
|
|
has 'debug' => ( is => 'ro', isa => 'Bool', default => 0 ); |
15
|
|
|
|
|
|
|
has 'password' => ( is => 'ro', isa => 'Maybe[Str]' ); |
16
|
|
|
|
|
|
|
has 'db' => ( is => 'ro', isa => 'Int', default => 0 ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _create_handle { |
19
|
0
|
|
|
0
|
|
|
my $self = shift; |
20
|
0
|
0
|
|
|
|
|
my $redis = Redis->new( |
21
|
|
|
|
|
|
|
'server' => $self->servers, |
22
|
|
|
|
|
|
|
'debug' => $self->debug, |
23
|
|
|
|
|
|
|
defined $self->password ? ( 'password' => $self->password ) : (), |
24
|
|
|
|
|
|
|
); |
25
|
0
|
|
|
|
|
|
$redis->select( $self->db ); |
26
|
0
|
|
|
|
|
|
return $redis; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'handle' => ( |
30
|
|
|
|
|
|
|
is => 'rw', isa => 'Redis', lazy => 1, |
31
|
|
|
|
|
|
|
default => sub { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
return $self->_create_handle; |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub reconnect { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
$self->handle( $self->_create_handle ); |
40
|
0
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub shutdown { |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
0
|
|
|
|
|
|
$self->handle->disconnect_all; |
46
|
0
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=encoding UTF-8 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Mail::MtPolicyd::Connection::Redis - a mtpolicy connection for redis databases |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 VERSION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
version 2.01 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
<Connection redis> |
68
|
|
|
|
|
|
|
server = "127.0.0.1:6379" |
69
|
|
|
|
|
|
|
db = 0 |
70
|
|
|
|
|
|
|
# password = "secret" |
71
|
|
|
|
|
|
|
</Connection> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 PARAMETERS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item server (default: 127.0.0.1:6379) |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The redis server to connect. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item debug (default: 0) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Set to 1 to enable debugging of redis connection. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item password (default: undef) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Set password if required for redis connection. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item db (default: 0) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Select a redis database to use. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This is free software, licensed under: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |