| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Hubot::Scripts::redisBrain; |
|
2
|
|
|
|
|
|
|
$Hubot::Scripts::redisBrain::VERSION = '0.1.10'; |
|
3
|
1
|
|
|
1
|
|
633
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
17
|
|
|
5
|
1
|
|
|
1
|
|
393
|
use Redis; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use JSON::XS; |
|
7
|
|
|
|
|
|
|
use Encode qw/encode_utf8 decode_utf8/; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub load { |
|
10
|
|
|
|
|
|
|
my ( $class, $robot ) = @_; |
|
11
|
|
|
|
|
|
|
my $coder = JSON::XS->new->convert_blessed; |
|
12
|
|
|
|
|
|
|
my $redis = Redis->new( server => $ENV{REDIS_SERVER} || '127.0.0.1:6379' ); |
|
13
|
|
|
|
|
|
|
print "connected to redis-server\n" if $ENV{DEBUG}; |
|
14
|
|
|
|
|
|
|
my $json = $redis->get('hubot:storage') || '{}'; |
|
15
|
|
|
|
|
|
|
$robot->brain->mergeData( decode_json( decode_utf8($json) ) ); |
|
16
|
|
|
|
|
|
|
$robot->brain->on( |
|
17
|
|
|
|
|
|
|
'save', |
|
18
|
|
|
|
|
|
|
sub { |
|
19
|
|
|
|
|
|
|
my ( $e, $data ) = @_; |
|
20
|
|
|
|
|
|
|
my $json = $coder->encode($data); |
|
21
|
|
|
|
|
|
|
$redis->set( 'hubot:storage', encode_utf8($json) ); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
$robot->brain->on( 'close', sub { $redis->quit } ); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Hubot::Scripts::redisBrain |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 VERSION |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
version 0.1.10 |
|
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 |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Hyungsuk Hong |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |