another refactor to use MSG and SEND all over
[MQR.git] / lib / MQR / Redis.pm
1 package MQR::Redis;
2
3 use AnyEvent::Redis;
4 use Carp qw(confess);
5 use Data::Dump qw(dump);
6
7 sub redis {
8         my $redis = AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
9         $redis->ping;
10         return $redis;
11 }
12
13 sub publish {
14         my ( $self, $channel, $body ) = @_;
15         $channel = join(' ', @$channel) if ref $channel eq 'ARRAY';
16         my $pub = redis;
17         $pub->publish( $channel, $body );
18         warn ">>>> ",dump($channel, $body);
19 }
20
21 1;