Riak::Light - Fast and lightweight Perl client for Riak
version 0.052
use Riak::Light; # create a new instance - using pbc only my $client = Riak::Light->new( host => '127.0.0.1', port => 8087 ); $client->is_alive() or die "ops, riak is not alive"; # store hashref into bucket 'foo', key 'bar' # will serializer as 'application/json' $client->put( foo => bar => { baz => 1024 }); # store text into bucket 'foo', key 'bar' $client->put( foo => baz => "sometext", 'text/plain'); # fetch hashref from bucket 'foo', key 'bar' my $hash = $client->get( foo => 'bar'); # delete hashref from bucket 'foo', key 'bar' $client->del(foo => 'bar'); # list keys in stream $client->get_keys(foo => sub{ my $key = $_[0]; # you should use another client inside this callback! $another_client->del(foo => $key); });
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.
Riak ip or hostname. There is no default.
Port of the PBC interface. There is no default.
R value setting for this client. Default 2.
W value setting for this client. Default 2.
DW value setting for this client. Default 2.
Boolean, if false each operation will return undef in case of error (stored in $@). Default is true.
Timeout for connection, write and read operations. Default is 0.5 seconds.
Timeout for read operations. Default is timeout value.
Timeout for write operations. Default is timeout value.
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 5 options (or you can set undef to avoid IO Timeout):
Riak::Light::Timeout::Alarm
uses alarm and Time::HiRes to control the I/O timeout. Does not work on Win32. (Not Safe)
Riak::Light::Timeout::Time::Out
uses Time::Out and Time::HiRes to control the I/O timeout. Does not work on Win32. (Not Safe)
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. Can block in Write Operations. Be Careful.
Riak::Light::Timeout::SetSockOpt
uses setsockopt to set SO_RCVTIMEO and SO_SNDTIMEO socket properties. Does not Work on NetBSD 6.0.
This is a Riak::Light::Driver instance, to be able to connect and perform requests to Riak over PBC interface.
$client->is_alive() or warn "ops... something is wrong: $@";
Perform a ping operation. Will return false in case of error (will store in $@).
try { $client->ping() } catch { "ops... something is wrong: $_" };
Perform a ping operation. Will die in case of error.
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 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 get instead.
$client->exists(bucket => 'key') or warn "key not found";
Perform a fetch operation but with head => 0, and the if there is something stored in the bucket/key.
$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 put_raw instead.
$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 put instead.
$client->del(bucket => key);
Perform a delete operation. Expects bucket and key names.
$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!
Net::Riak
Data::Riak
Data::Riak::Fast
Tiago Peczenyj <tiago.peczenyj@gmail.com>
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.
To install Riak::Light, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Riak::Light
CPAN shell
perl -MCPAN -e shell install Riak::Light
For more information on module installation, please visit the detailed CPAN module installation guide.