extract common redis code
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 30 Aug 2010 21:06:08 +0000 (23:06 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 30 Aug 2010 21:06:08 +0000 (23:06 +0200)
lib/MQR/Redis.pm [new file with mode: 0644]
t/10-Redis.t [new file with mode: 0755]

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;
diff --git a/t/10-Redis.t b/t/10-Redis.t
new file mode 100755 (executable)
index 0000000..07b76e5
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use Test::More tests => 3;
+
+use lib 'lib';
+
+BEGIN {
+       use_ok( 'MQR::Redis' );
+}
+
+ok( my $o = MQR::Redis->redis, 'redis' );
+
+ok( MQR::Redis->publish( 'TEST' => $0 ), 'publish' );
+