NAME
Riak::Light - Fast and lightweight Perl client for Riak
VERSION
version 0.01
DESCRIPTION
Riak::Light is a very light (and fast) perl client for Riak using PBC interface. Support only basic operations like ping, get, put and del. Is flexible to change the timeout backend for I/O operations and can suppress 'die' in case of error (autodie) using the configuration. There is no auto-reconnect option.
ATTRIBUTES
host
Riak ip or hostname. There is no default.
port
Port of the PBC interface. There is no default.
r
R value setting for this client. Default 2.
w
W value setting for this client. Default 2.
dw
DW value setting for this client. Default 2.
autodie
Boolean, if false each operation will return undef in case of error (stored in $@).
(Default is true)
timeout
Timeout for connection, write and read operations. Default is 0.5 seconds.
in_timeout
Timeout for read operations. Default is timeout value.
out_timeout
Timeout for write operations. Default is timeout value.
timeout_provider
Can change the backend for timeout. The default value is IO::Socket::INET and there is only support to connection timeout.
IMPORTANT: in case of any timeout error, the socket between this client and the Riak server will be closed.
To support I/O timeout you can choose 4 options:
Riak::Light::Timeout::Alarm
uses Time::Out and Time::HiRes to control the I/O timeout
Riak::Light::Timeout::Select
uses IO::Select to control the I/O timeout
Riak::Light::Timeout::SelectOnWrite
uses IO::Select to control only Output Operations
Riak::Light::Timeout::SetSockOpt
uses setsockopt to set SO_RCVTIMEO and SO_SNDTIMEO socket properties. Experimental.
driver
This is a Riak::Light::Driver instance, to be able to connect and perform requests to Riak over PBC interface.
METHODS
is_alive
$client->is_alive() or warn "ops... something is wrong: $@";
Perform a ping operation. Will return false in case of error (will store in $@).
get
my $value_or_reference = $client->get(bucket => 'key');
Perform a fetch operation. Expects bucket and key names. Decode the json into a Perl structure. if the content_type is 'application/json'. If you need the raw data you can use L<get_raw>.
get_raw
my $scalar_value = $client->get_raw(bucket => 'key');
Perform a fetch operation. Expects bucket and key names. Return the raw data. If you need decode the json, you should use L<get> instead.
put
$client->put(bucket => key => { some_values => [1,2,3] });
$client->put(bucket => key => 'text', 'plain/text');
Perform a store operation. Expects bucket and key names, the value and the content type (optional, default is 'application/json'). Will encode the structure in json string if necessary. If you need only store the raw data you can use L<put_raw> instead.
put_raw
$client->put_raw(bucket => key => encode_json({ some_values => [1,2,3] }), 'application/json');
$client->put_raw(bucket => key => 'text');
Perform a store operation. Expects bucket and key names, the value and the content type (optional, default is 'plain/text'). Will encode the raw data. If you need encode the structure you can use L<put> instead.
del
$client->del(bucket => key);
Perform a delete operation. Expects bucket and key names.
get_keys
$client->get_keys(foo => sub{
my $key = $_[0];
# you should use another client inside this callback!
$another_client->del(foo => $key);
});
Perform a list keys operation. Receive a callback and will call it for each key. You can't use this callback to perform other operations!
NAME
Riak::Light - Fast and lightweight Perl client for Riak
VERSION
version 0.001
SYNOPSIS use Riak::Light;
# create a new instance - using pbc only
my $client = Riak::Light->new(
host => '127.0.0.1',
port => 8087
);
try { $client->ping() };
# store hashref into bucket 'foo', key 'bar'
$client->put( foo => bar => { baz => 1024 }, 'application/json');
# fetch hashref from bucket 'foo', key 'bar'
my $hash = $client->get( foo => 'bar');
# delete hashref from bucket 'foo', key 'bar'
$client->del(foo => 'bar');
SEE ALSO
AUTHOR
Tiago Peczenyj <tiago.peczenyj@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Weborama.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.