DR-Tarantool
view release on metacpan or search on metacpan
lib/DR/Tarantool/MsgPack/AsyncClient.pm view on Meta::CPAN
my $reconnect_period = $opts{reconnect_period} || 0;
my $reconnect_always = $opts{reconnect_always} || 0;
DR::Tarantool::MsgPack::LLClient->connect(
host => $host,
port => $port,
user => $user,
password => $password,
reconnect_period => $reconnect_period,
reconnect_always => $reconnect_always,
sub {
my ($client) = @_;
my $self;
if (ref $client) {
$self = bless {
llc => $client,
spaces => $spaces,
} => ref($class) || $class;
} else {
$self = $client;
}
$cb->( $self );
}
);
return;
}
sub _llc { return $_[0]{llc} if ref $_[0]; 'DR::Tarantool::MsgPack::LLClient' }
sub _cb_default {
my ($res, $s, $cb) = @_;
if ($res->{status} ne 'ok') {
$cb->($res->{status} => $res->{CODE}, $res->{ERROR});
return;
}
if ($s) {
$cb->(ok => $s->tuple_class->unpack( $res->{DATA}, $s ), $res->{CODE});
return;
}
unless ('ARRAY' eq ref $res->{DATA}) {
$cb->(ok => $res->{DATA}, $res->{CODE});
return;
}
unless (@{ $res->{DATA} }) {
$cb->(ok => undef, $res->{CODE});
return;
}
$cb->(ok => DR::Tarantool::Tuple->new($res->{DATA}), $res->{CODE});
return;
}
=head1 Worker methods
All methods accept callbacks which are invoked with the following
arguments:
=over
=item status
On success, this field has value 'ok'. The value of this parameter
determines the contents of the rest of the callback arguments.
=item a tuple or tuples or an error code
On success, the second argument contains tuple(s) produced by the
request. On error, it contains the server error code.
=item errorstr
Error string in case of an error.
sub {
if ($_[0] eq 'ok') {
my ($status, $tuples) = @_;
...
} else {
my ($status, $code, $errstr) = @_;
...
}
}
=back
=head2 ping
Ping the server.
$client->ping(sub { ... });
=head2 insert, replace
Insert/replace a tuple into a space.
$client->insert('space', [ 1, 'Vasya', 20 ], sub { ... });
$client->replace('space', [ 2, 'Petya', 22 ], sub { ... });
=head2 call_lua
Call Lua function.
$client->call_lua(foo => ['arg1', 'arg2'], sub { });
=head2 select
Select a tuple (or tuples) from a space by index.
$client->select('space_name', 'index_name', [ 'key' ], %opts, sub { .. });
Options can be:
( run in 1.663 second using v1.01-cache-2.11-cpan-39bf76dae61 )