Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- $|=1;
- use strict;
- use lib '/home/jzawodn/code/AnyEvent-Redis/lib';
- use AnyEvent::Redis;
- my $host = 'localhost';
- my $port = 6379;
- my @chan = 'a'..'z'; # which queues/channels to check
- my $command_timeout = 1; # how long to wait for a response
- my $done_cv = AnyEvent->condvar;
- $done_cv->begin;
- my $redis = AnyEvent::Redis->new(host => $host, port => $port,
- on_error => sub { warn @_; $done_cv->end; }
- );
- sub handler;
- sub handler {
- my ($stuff) = @_;
- if ($stuff) {
- my ($key, $msg) = @$stuff;
- print "got $msg via $key\n";
- } else {
- print "blpop timeout\n";
- }
- $redis->blpop(@chan, $command_timeout, sub { handler(@_); });
- };
- handler();
- $done_cv->recv;
- exit;
Add Comment
Please, Sign In to add comment