Guest User

Untitled

a guest
Jun 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. $|=1;
  3. use strict;
  4. use lib '/home/jzawodn/code/AnyEvent-Redis/lib';
  5. use AnyEvent::Redis;
  6.  
  7. my $host = 'localhost';
  8. my $port = 6379;
  9. my @chan = 'a'..'z'; # which queues/channels to check
  10. my $command_timeout = 1; # how long to wait for a response
  11.  
  12. my $done_cv = AnyEvent->condvar;
  13. $done_cv->begin;
  14.  
  15. my $redis = AnyEvent::Redis->new(host => $host, port => $port,
  16. on_error => sub { warn @_; $done_cv->end; }
  17. );
  18.  
  19. sub handler;
  20. sub handler {
  21. my ($stuff) = @_;
  22. if ($stuff) {
  23. my ($key, $msg) = @$stuff;
  24. print "got $msg via $key\n";
  25. } else {
  26. print "blpop timeout\n";
  27. }
  28. $redis->blpop(@chan, $command_timeout, sub { handler(@_); });
  29. };
  30.  
  31. handler();
  32. $done_cv->recv;
  33.  
  34. exit;
Add Comment
Please, Sign In to add comment