Created
October 29, 2010 17:05
-
-
Save jzawodn/653910 to your computer and use it in GitHub Desktop.
AnyEvent Perl GET loop. No memory leak.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $key = 'foo'; | |
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) { | |
print "got $stuff via $key\n"; | |
} else { | |
print "no data\n"; | |
} | |
$redis->get($key, sub { handler(@_); }); | |
}; | |
handler(); | |
$done_cv->recv; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare with: http://gist.github.com/653912