line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Redis; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
22815
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
16
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Mojolicious::Plugin::Redis - Simply use Redis in Mojolicious |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.03 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
BEGIN { |
17
|
2
|
|
|
2
|
|
35
|
$Mojolicious::Plugin::Redis::VERSION = '0.03'; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
820
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
10617
|
|
|
2
|
|
|
|
|
15
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
12138
|
use Redis; |
|
2
|
|
|
|
|
116850
|
|
|
2
|
|
|
|
|
443
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 INSTALLATION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
To install this module, run the following commands: |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
perl Build.PL |
29
|
|
|
|
|
|
|
./Build |
30
|
|
|
|
|
|
|
./Build test |
31
|
|
|
|
|
|
|
./Build install |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Provides a few helpers to ease the use of Redis in your Mojolicious application. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Mojolicious::Plugin::Redis |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub startup { |
40
|
|
|
|
|
|
|
my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$self->plugin('redis', { |
43
|
|
|
|
|
|
|
server => 'localhost:6379', |
44
|
|
|
|
|
|
|
debug => 0, |
45
|
|
|
|
|
|
|
encoding => undef, # Disable the automatic utf8 encoding => much more performance |
46
|
|
|
|
|
|
|
helper => 'db' |
47
|
|
|
|
|
|
|
}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 CONFIGURATION OPTIONS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
helper (optional) The name to give to the easy-access helper if you want to change it's name from the default |
53
|
|
|
|
|
|
|
no_helper (optional) When set to true, no helper will be installed. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
All other options passed to the plugin are used to connect to Redis. In other words ANY option can be sended to Redis module. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 HELPERS/ATTRIBUTES |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 redis_connection |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This plugin attribute holds the Redis::Connection object, use this if you need to access it for some reason. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 db |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This helper will return the database handler. If you have renamed the helper, use that name instead of 'db' in the example below :) |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub someaction { |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# ping Redis server |
71
|
|
|
|
|
|
|
$self->db->PING(); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# get value of 'foo' named key |
74
|
|
|
|
|
|
|
$self->db->GET('foo'); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub register { |
81
|
1
|
|
|
1
|
1
|
73
|
my $self = shift; |
82
|
1
|
|
|
|
|
2
|
my $app = shift; |
83
|
1
|
|
50
|
|
|
7
|
my $conf = shift || {}; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
50
|
|
|
9
|
$conf->{helper} ||= 'db'; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
0
|
|
16
|
$app->attr('redis_connection' => sub { Redis->new(%$conf) }); |
|
0
|
|
|
|
|
0
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$app->helper($conf->{helper} => sub { |
90
|
0
|
|
|
0
|
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
return $self->app->redis_connection; |
92
|
1
|
50
|
|
|
|
204
|
}) unless($conf->{nohelper}); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DEVELOPMENT |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 Repository |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
http://github.com/Meettya/Mojolicious-Plugin-Redis |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Meettya, C |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 BUGS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
109
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
110
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SUPPORT |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
perldoc Mojolicious::Plugin::Redis |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
You can also look for information at: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * CPAN Ratings |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * Search CPAN |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Ben van Staveren (inspiration from L), so I didn't have to write it myself, just copy-paste. |
146
|
|
|
|
|
|
|
Sergey Zasenko for test fix. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Copyright 2011 Meettya, all rights reserved. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
153
|
|
|
|
|
|
|
under the same terms as Perl itself. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; # End of Mojolicious::Plugin::Redis |