EV-Memcached

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        timer; setting it to 0 still defers through the event loop (no
        synchronous retry recursion).

    max_reconnect_attempts => $num
        Give up after this many consecutive failures and emit "max reconnect
        attempts reached". 0 = unlimited (default).

   Authentication
    username => $str
    password => $str
        SASL PLAIN credentials. When both are set, the client authenticates
        after every successful connect (and reconnect). Pre-connect commands sit
        in the waiting queue until SASL completes. Requires a memcached build
        with SASL support and the "-S" flag.

   Event handlers
    on_error => $cb->($errstr)
        Connection-level error callback. Default: write the message to "STDERR"
        via "warn". Callbacks are run under "G_EVAL", so any "die" in a custom
        handler is demoted to a warning -- use an explicit flag if you need to
        terminate.

eg/sasl_auth.pl  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use EV::Memcached;

$| = 1;

# SASL PLAIN authentication example.
# Requires memcached started with: memcached -S -B binary
# And SASL credentials configured via saslpasswd2.

# Option 1: Auto-auth via constructor (recommended)
# Credentials are sent automatically on every connect/reconnect.
{
    my $mc = EV::Memcached->new(
        host     => $ENV{MC_HOST} // '127.0.0.1',
        port     => $ENV{MC_PORT} // 11211,
        username => $ENV{MC_USER} // 'testuser',
        password => $ENV{MC_PASS} // 'testpass',
        on_error => sub { warn "error: @_\n"; EV::break },

lib/EV/Memcached.pm  view on Meta::CPAN

=back

=head3 Authentication

=over

=item username => $str

=item password => $str

SASL PLAIN credentials. When both are set, the client authenticates
after every successful connect (and reconnect). Pre-connect commands
sit in the waiting queue until SASL completes. Requires a memcached
build with SASL support and the C<-S> flag.

=back

=head3 Event handlers

=over

t/07_sasl.t  view on Meta::CPAN

unless ($port) {
    # Try to auto-setup SASL memcached
    my $saslpasswd = '/usr/sbin/saslpasswd2';
    unless (-x $saslpasswd) {
        plan skip_all => "saslpasswd2 not found (install sasl2-bin)";
    }

    my $dir = "/tmp/evmc_sasl_test_$$";
    mkdir $dir, 0755;

    # Create SASL credentials
    open my $pw, '|-', "$saslpasswd -a memcached -c -f $dir/sasldb2 -p $user 2>/dev/null"
        or plan skip_all => "cannot run saslpasswd2";
    print $pw $pass;
    close $pw;
    unless (-f "$dir/sasldb2") {
        system("rm -rf $dir");
        plan skip_all => "saslpasswd2 failed to create db";
    }

    # SASL config



( run in 1.228 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )