AnyEvent-Memcached
view release on metacpan or search on metacpan
lib/AnyEvent/Memcached.pm view on Meta::CPAN
my ($values,$err) = shift;
$err and warn "Get failed: @_";
for (0 .. $#values/2) {
my ($key,$value) = @$values[$_*2,$_*2+1];
}
} );
=head1 DESCRIPTION
Asyncronous C<memcached/memcachedb> client for L<AnyEvent> framework
=head1 NOTICE
There is a notices in L<Cache::Memcached::AnyEvent> related to this module. They all has been fixed
=over 4
=item Prerequisites
We no longer need L<Object::Event> and L<Devel::Leak::Cb>. At all, the dependency list is like in L<Cache::Memcached> + L<AnyEvent>
=item Binary protocol
It seems to me, that usage of binary protocol from pure perl gives very little advantage. So for now I don't implement it
=item Unimplemented Methods
There is a note, that get_multi is not implementeted. In fact, it was implemented by method L</get>, but the documentation was wrong.
=back
In general, this module follows the spirit of L<AnyEvent> rather than correspondence to L<Cache::Memcached> interface.
=cut
use common::sense 2;m{
use strict;
use warnings;
}x;
use Carp;
use AnyEvent 5;
#use Devel::Leak::Cb;
use AnyEvent::Socket;
use AnyEvent::Handle;
use AnyEvent::Connection;
use AnyEvent::Connection::Util;
use AnyEvent::Memcached::Conn;
use Storable ();
use AnyEvent::Memcached::Peer;
use AnyEvent::Memcached::Hash;
use AnyEvent::Memcached::Buckets;
# flag definitions
use constant F_STORABLE => 1;
use constant F_COMPRESS => 2;
# size savings required before saving compressed value
use constant COMPRESS_SAVINGS => 0.20; # percent
our $HAVE_ZLIB;
BEGIN {
$HAVE_ZLIB = eval "use Compress::Zlib (); 1;";
}
=head1 METHODS
=head2 new %args
Currently supported options:
=over 4
=item servers
=item namespace
=item debug
=item cv
=item compress_threshold
=item compress_enable
=item timeout
=item hasher
If set, will use instance of this class for hashing instead of default.
For implementing your own hashing, see sources of L<AnyEvent::Memcached::Hash> and L<AnyEvent::Memcached::Hash::With::Next>
=item noreply
If true, additional connection will established for noreply commands.
=item cas
If true, will enable cas/gets commands (since they are not suppotred in memcachedb)
=back
=cut
sub new {
my $self = bless {}, shift;
my %args = @_;
$self->{namespace} = exists $args{namespace} ? delete $args{namespace} : '';
for (qw( debug cv compress_threshold compress_enable timeout noreply cas)) {
$self->{$_} = exists $args{$_} ? delete $args{$_} : 0;
}
$self->{timeout} ||= 3;
$self->{_bucker} = $args{bucker} || 'AnyEvent::Memcached::Buckets';
$self->{_hasher} = $args{hasher} || 'AnyEvent::Memcached::Hash';
$self->set_servers(delete $args{servers});
$self->{compress_enable} and !$HAVE_ZLIB and carp("Have no Compress::Zlib installed, but have compress_enable option");
carp "@{[ keys %args ]} options are not supported yet" if %args;
Carp::confess "Invalid characters in 'namespace' option: '$self->{namespace}'" if $self->{namespace} =~ /[\x00-\x20\x7F]/;
$self;
}
=head2 set_servers
Setup server list
( run in 0.499 second using v1.01-cache-2.11-cpan-39bf76dae61 )