Skip to content

Instantly share code, notes, and snippets.

@qknight
Created February 29, 2016 13:52
Show Gist options
  • Save qknight/ab5a57b110e283707b4b to your computer and use it in GitHub Desktop.
Save qknight/ab5a57b110e283707b4b to your computer and use it in GitHub Desktop.
#!/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