I have the code below to do non blocking rpush into a redis server When I run this for just 1 rpush , the code works fine But when I run this in a while loop the script hangs after the first execution. Why ?
#!/usr/bin/perl
use AnyEvent;
use AnyEvent::Redis::RipeRedis;
use strict;
#my $cv = AE::cv();
my $redis = AnyEvent::Redis::RipeRedis->new(
host => 'localhost',
port => '6379',
);
my $i=0;
my $cv;
while($i++ < 5) {
$cv = AnyEvent->condvar;
$redis->rpush( 'list', "1","2","3",
{ on_done => sub {
my $data = shift;
print "$data\n";
},
}
);
$cv->recv();
}
$redis->quit(
sub {$cv->send();}
);
$cv->recv();