line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hubot::Scripts::redisBrain; |
2
|
|
|
|
|
|
|
$Hubot::Scripts::redisBrain::VERSION = '0.1.9'; |
3
|
1
|
|
|
1
|
|
1246
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
179
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
30011
|
use Redis; |
|
1
|
|
|
|
|
148152
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
1246
|
use JSON::XS; |
|
1
|
|
|
|
|
7834
|
|
|
1
|
|
|
|
|
71
|
|
7
|
1
|
|
|
1
|
|
11
|
use Encode qw/encode_utf8 decode_utf8/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
313
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub load { |
10
|
0
|
|
|
0
|
0
|
|
my ( $class, $robot ) = @_; |
11
|
0
|
|
|
|
|
|
my $coder = JSON::XS->new->convert_blessed; |
12
|
0
|
|
0
|
|
|
|
my $redis = Redis->new( server => $ENV{REDIS_SERVER} || '127.0.0.1:6379' ); |
13
|
0
|
0
|
|
|
|
|
print "connected to redis-server\n" if $ENV{DEBUG}; |
14
|
0
|
|
0
|
|
|
|
my $json = $redis->get('hubot:storage') || '{}'; |
15
|
0
|
|
|
|
|
|
$robot->brain->mergeData( decode_json( decode_utf8($json) ) ); |
16
|
|
|
|
|
|
|
$robot->brain->on( |
17
|
|
|
|
|
|
|
'save', |
18
|
|
|
|
|
|
|
sub { |
19
|
0
|
|
|
0
|
|
|
my ( $e, $data ) = @_; |
20
|
0
|
|
|
|
|
|
my $json = $coder->encode($data); |
21
|
0
|
|
|
|
|
|
$redis->set( 'hubot:storage', encode_utf8($json) ); |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
); |
24
|
0
|
|
|
0
|
|
|
$robot->brain->on( 'close', sub { $redis->quit } ); |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Hubot::Scripts::redisBrain |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 VERSION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
version 0.1.9 |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 CONFIGURATION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item REDIS_SERVER |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
C<127.0.0.1:6379> is default to use. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SEE ALSO |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
L<https://github.com/github/hubot-scripts/blob/master/src/scripts/redis-brain.coffee> |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Hyungsuk Hong <hshong@perl.kr> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |