Skip to content

Instantly share code, notes, and snippets.

@realdecisions
Created March 3, 2015 22:02
Show Gist options
  • Save realdecisions/ea5c6da25af3b919007b to your computer and use it in GitHub Desktop.
Save realdecisions/ea5c6da25af3b919007b to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use FindBin;use lib "$FindBin::Bin/../blib/lib";
use AnyEvent::HTTP::Server;
use EV;
use Cache::Memcached::Fast;
use JSON::XS;
use Data::Dumper;
my $_JSON = JSON::XS->new->utf8;
my $mem = Cache::Memcached::Fast->new({servers=>[qw/127.0.0.1:11211/]});
$mem->set('counter:1',0);
$mem->disconnect_all;
my $server = AnyEvent::HTTP::Server->new(
port => 8111
,
cb => sub {
my $id = 1;
my $counter = $mem->incr('counter:'.$id);
return 200, $_JSON->encode({counter=>$counter}),'Content-Type'=>'application/json; charset=UTF-8';
},
);
$server->listen;
$server->accept;
EV::loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment