Created
February 29, 2016 13:52
-
-
Save qknight/ab5a57b110e283707b4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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/env perl | |
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Redis::RipeRedis; | |
my $cv = AE::cv(); | |
my $redis; | |
$redis = AnyEvent::Redis::RipeRedis->new( | |
host => 'localhost', | |
port => '6379', | |
password => 'redis_pass', | |
reconnect => 1, # 1 by default | |
on_connect => sub { | |
print "Connected to Redis server\n"; | |
}, | |
on_disconnect => sub { | |
print "Disconnected from Redis server\n"; | |
}, | |
); | |
my $timer; | |
$timer = AE::timer( 0, 1, | |
sub { | |
$redis->incr( 'foo', | |
sub { | |
my $data = shift; | |
if ( @_ ) { | |
my $err_msg = shift; | |
warn $err_msg; | |
# Here you can repeat command or do nothing | |
return; | |
} | |
print "$data\n"; | |
}, | |
); | |
}, | |
); | |
my $on_signal = sub { | |
print "Stopped\n"; | |
$cv->send(); | |
}; | |
my $int_w = AE::signal( INT => $on_signal ); | |
my $term_w = AE::signal( TERM => $on_signal ); | |
$cv->recv(); | |
$redis->disconnect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment