DR::Tarantool::LLClient - low level async client for tarantool
DR::Tarantool::LLClient->connect( host => '127.0.0.1', port => '33033', cb => { my ($tnt) = @_; ... } ); $tnt->ping( sub { .. } ); $tnt->insert(0, [ 1, 2, 3 ], sub { ... }); $tnt->select(1, 0, [ [ 1, 2 ], [ 3, 4 ] ], sub { ... }); $tnt->update(0, [ 1 ], [ [ 1 => add pack 'L<', 1 ] ], sub { ... }); $tnt->call_lua( 'box.select', [ 0, 1, 2 ], sub { ... });
The module provides low-level interface to tarantool
All methods receive callback as the last argument. The callback receives HASHREF value with the following fields:
Done status:
Fatal error was happenned. Server closed connection or returned broken package.
Internal driver error.
Request wasn't done: database returned error.
Request was done.
If an error was happenned contains error description.
Contains reply code.
Contains request id. (see protocol documentation)
Contains request type (see protocol documentation)
Contains count of returned tuples.
Contains returned tuples (ARRAYREF of ARRAYREF).
If You use NUM or NUM64 values in database You have to pack them before requests and unpack them after response by hand. This is low-level driver :).
Creates a connection to tarantool
DR::Tarantool::LLClient->connect( host => '127.0.0.1', port => '33033', cb => { my ($tnt) = @_; ... } );
Host and port to connect.
Interval to reconnect after fatal errors or unsuccessful connects. If the field is defined and more than zero driver will try to reconnect server using this interval.
Important: driver wont reconnect after the first unsuccessful connection. It will call callback instead.
Constantly trying to reconnect even after the first unsuccessful connection.
Done callback. The callback will receive a client instance that is already connected with server or error string.
Returns TRUE if driver and server are connected with.
Returns string that informs You about status of connection. Return value can be:
Connection is established
Connection isn't established yet, or was disconnected.
Driver tries connecting server
Driver tried connecting but receives an error. Driver can repeat connecting processes (see reconnect_period option).
Pings tarantool.
$tnt->ping( sub { .. } );
Inserts tuple.
$tnt->insert(0, [ 1, 2, 3 ], sub { ... }); $tnt->insert(0, [ 4, 5, 6 ], $flags, sub { .. });
Selects tuple(s).
$tnt->select(1, 0, [ [ 1, 2 ], [ 3, 4 ] ], sub { ... }); $tnt->select(1, 0, [ [ 1, 2 ], [ 3, 4 ] ], 1, sub { ... }); $tnt->select(1, 0, [ [ 1, 2 ], [ 3, 4 ] ], 1, 2, sub { ... });
If limit isn't defined or zero select will extract all records without limit.
Default value is 0.
Updates tuple.
$tnt->update(0, [ 1 ], [ [ 1 => add 1 ] ], sub { ... }); $tnt->update( 0, # space [ 1 ], # key [ [ 1 => add 1 ], [ 2 => add => 1 ], # operations $flags, # flags sub { ... } # callback ); $tnt->update(0, [ 1 ], [ [ 1 => add 1 ] ], $flags, sub { ... });
Deletes tuple.
$tnt->delete( 0, [ 1 ], sub { ... }); $tnt->delete( 0, [ 1 ], $flags, sub { ... });
calls lua function.
$tnt->call_lua( 'box.select', [ 0, 1, 2 ], sub { ... }); $tnt->call_lua( 'box.select', [ 0, 1, 2 ], $flags, sub { ... });
Returns code of last operation (undef if there was no operation done).
Returns error string of last operation (undef if there was no error).
The module can log requests/responses. You can turn logging on by environment variables:
LLClient will record all requests/responses into the directory.
LLClient will record requests/responses into the directory if an error was happened.
Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org> Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru> This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License.
The project is placed git repo on github: https://github.com/unera/dr-tarantool/.
To install DR::Tarantool, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DR::Tarantool
CPAN shell
perl -MCPAN -e shell install DR::Tarantool
For more information on module installation, please visit the detailed CPAN module installation guide.