EV::Etcd

Async etcd v3 client for Perl using native gRPC Core C API and EV/libev.

Synopsis

use EV;
use EV::Etcd;

my $client = EV::Etcd->new(
    endpoints => ['127.0.0.1:2379'],
);

# Put
$client->put('/my/key', 'value', sub {
    my ($resp, $err) = @_;
    die $err->{message} if $err;
    say "Revision: $resp->{header}{revision}";
});

# Get
$client->get('/my/key', sub {
    my ($resp, $err) = @_;
    die $err->{message} if $err;
    say "Value: $resp->{kvs}[0]{value}";
});

# Watch
$client->watch('/my/key', sub {
    my ($resp, $err) = @_;
    for my $event (@{$resp->{events}}) {
        say "$event->{type} on $event->{kv}{key}";
    }
});

EV::run;

Features

Architecture

┌─────────────────────────┐
│   EV::Etcd (Perl API)   │
├─────────────────────────┤
│      Etcd.xs (XS)       │
├─────────────────────────┤
│  gRPC Core + protobuf-c │
├─────────────────────────┤
│   libev (event loop)    │
└─────────────────────────┘

A dedicated pthread polls the gRPC completion queue and signals the main EV event loop via ev_async. All Perl callbacks run in the main thread.

Requirements

System packages

Debian/Ubuntu:

apt install libgrpc-dev libgrpc++-dev libprotobuf-c-dev pkg-config

macOS:

brew install grpc protobuf-c pkg-config

FreeBSD:

pkg install grpc protobuf-c pkgconf

Install

cpanm EV
perl Makefile.PL
make
make test
make install

Documentation

Full API documentation is in the module POD:

perldoc EV::Etcd

License

Same terms as Perl itself.