line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Dancer-Plugin-Redis |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is copyright (c) 2014 by celogeek . |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
package Dancer::Plugin::Redis; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: easy database connections for Dancer applications |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
348664
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
14
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.8'; # VERSION |
16
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
17
|
1
|
|
|
1
|
|
782
|
use Dancer::Plugin; |
|
1
|
|
|
|
|
1401
|
|
|
1
|
|
|
|
|
65
|
|
18
|
1
|
|
|
1
|
|
7
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
19
|
1
|
|
|
1
|
|
10
|
use Redis 1.955; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
201
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $_settings; |
22
|
|
|
|
|
|
|
my $_handles; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub redis { |
25
|
1
|
|
|
1
|
|
2217
|
my @args = @_; |
26
|
1
|
|
|
|
|
7
|
my ( undef, $name ) = plugin_args(@args); |
27
|
1
|
50
|
|
|
|
7
|
$name = "_default" if not defined $name; |
28
|
1
|
50
|
|
|
|
5
|
return $_handles->{$name} if exists $_handles->{$name}; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
33
|
|
|
10
|
$_settings ||= plugin_setting; |
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
23
|
my $conf |
33
|
|
|
|
|
|
|
= $name eq '_default' |
34
|
|
|
|
|
|
|
? $_settings |
35
|
|
|
|
|
|
|
: $_settings->{connections}->{$name}; |
36
|
1
|
50
|
|
|
|
4
|
croak "$name is not defined in your redis conf, please check the doc" |
37
|
|
|
|
|
|
|
unless defined $conf; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
50
|
|
|
21
|
return $_handles->{$name} = Redis->new( |
40
|
|
|
|
|
|
|
server => $conf->{server}, |
41
|
|
|
|
|
|
|
debug => $conf->{debug}, |
42
|
|
|
|
|
|
|
encoding => $conf->{encoding}, |
43
|
|
|
|
|
|
|
reconnect => $conf->{reconnect} // 60, |
44
|
|
|
|
|
|
|
password => $conf->{password}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
register redis => \&redis; |
50
|
|
|
|
|
|
|
register_plugin for_versions => [ 1, 2 ]; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |