| 1 | package Mail::MtPolicyd::Connection::Redis; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = '2.01'; # VERSION | |||||||||
| 6 | # ABSTRACT: a mtpolicy connection for redis databases | ||||||||||
| 7 | |||||||||||
| 8 | 1 | extends 'Mail::MtPolicyd::Connection'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Redis; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 1 | has 'server' => ( is => 'ro', isa => 'Str', default => '127.0.0.1:6379' ); | |||||||||
| 14 | 1 | has 'debug' => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||
| 15 | 1 | has 'password' => ( is => 'ro', isa => 'Maybe[Str]' ); | |||||||||
| 16 | 1 | has 'db' => ( is => 'ro', isa => 'Int', default => 0 ); | |||||||||
| 17 | |||||||||||
| 18 | sub _create_handle { | ||||||||||
| 19 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_create_handle: not called CC=2 SCAR=17.9
| |||||||||||
| 20 | 0 | ▶ | my $redis = Redis->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | return $self->_create_handle; | |||||||||
| 34 | }, | ||||||||||
| 35 | 1 | ); | |||||||||
| 36 | |||||||||||
| 37 | sub reconnect { | ||||||||||
| 38 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
reconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 39 | 0 | $self->handle( $self->_create_handle ); | |||||||||
| 40 | 0 | return; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | sub shutdown { | ||||||||||
| 44 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | 0 | $self->handle->disconnect_all; | |||||||||
| 46 | 0 | return; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 1 | 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 | ||||||||||