AnyEvent-Redis
view release on metacpan or search on metacpan
lib/AnyEvent/Redis.pm view on Meta::CPAN
package AnyEvent::Redis;
use strict;
use 5.008_001;
our $VERSION = '0.24';
use constant DEBUG => $ENV{ANYEVENT_REDIS_DEBUG};
use AnyEvent;
use AnyEvent::Handle;
use AnyEvent::Socket;
use AnyEvent::Redis::Protocol;
use Carp qw( croak confess );
use Encode ();
use Scalar::Util qw(weaken);
our $AUTOLOAD;
sub new {
my ($class, %args) = @_;
my $host = delete $args{host} || '127.0.0.1';
my $port = delete $args{port} || 6379;
if (my $encoding = $args{encoding}) {
$args{encoding} = Encode::find_encoding($encoding);
croak qq{Encoding "$encoding" not found} unless ref $args{encoding};
}
bless {
host => $host,
port => $port,
pending_cvs => [],
%args,
}, $class;
}
sub run_cmd {
my $self = shift;
my $cmd = shift;
$self->{cmd_cb} or return $self->connect($cmd, @_);
$self->{cmd_cb}->($cmd, @_);
}
sub DESTROY { }
sub AUTOLOAD {
my $self = shift;
(my $method = $AUTOLOAD) =~ s/.*:://;
$self->run_cmd($method, @_);
}
sub all_cv {
my $self = shift;
$self->{all_cv} = shift if @_;
$self->{all_cv} ||= AE::cv;
}
sub cleanup {
my $self = shift;
delete $self->{cmd_cb};
delete $self->{sock};
$self->{on_error}->(@_) if $self->{on_error};
$self->{on_cleanup}->(@_) if $self->{on_cleanup};
for (splice(@{$self->{pending_cvs}}),
( run in 1.827 second using v1.01-cache-2.11-cpan-39bf76dae61 )