extract common redis code
[MQR.git] / lib / MQR / Redis.pm
diff --git a/lib/MQR/Redis.pm b/lib/MQR/Redis.pm
new file mode 100644 (file)
index 0000000..119cb46
--- /dev/null
@@ -0,0 +1,19 @@
+package MQR::Redis;
+
+use AnyEvent::Redis;
+use Carp qw(confess);
+use Data::Dump qw(dump);
+
+sub redis {
+       AnyEvent::Redis->new( host => $ENV{REDIS_HOST}, port => $ENV{REDIS_PORT}, on_error => sub { confess @_ } );
+}
+
+sub publish {
+       my ( $channel, $body ) = @_;
+       $channel = join(' ', @$channel) if ref $channel eq 'ARRAY';
+       my $pub = redis;
+       $pub->publish( $channel, $body );
+       warn ">>>> ",dump($channel, $body);
+}
+
+1;