<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Riak::Client - Fast and lightweight Perl client for Riak

VERSION
    version 1.92

SYNOPSIS
      use Riak::Client;

      # normal mode
      my $client = Riak::Client-&gt;new(
        host =&gt; '127.0.0.1',
        port =&gt; 8087,
        r =&gt; 2,
        w =&gt; 2,
        dw =&gt; 1,
        connection_timeout =&gt; 5,
        read_timeout =&gt; 5,
        write_timeout =&gt; 5,
        no_auto_connect =&gt; 0,
      );

      # AnyEvent mode
      my $client = Riak::Client-&gt;new(
        host =&gt; '127.0.0.1',
        port =&gt; 8087
        anyevent_mode =&gt; 1,
      );

      $client-&gt;is_alive() or die "riak is not alive";

      # store hashref. will be serialized as JSON
      $client-&gt;put( 'bucket_name', 'key_name', { some =&gt; 'structure' } );

      # store text
      $client-&gt;put( 'bucket_name', 'key_name', 'sometext', 'text/plain' );

      # store raw data
      $client-&gt;put_raw( 'bucket_name', 'key_name', 'rawdata' );

      # fetch hashref
      my $hash = $client-&gt;get( 'bucket_name', 'key_name' );

      # fetch raw data
      my $text = $client-&gt;get_raw( 'bucket_name', 'key_name');

      # delete data
      $client-&gt;del( 'bucket_name', 'key_name');

      # AnyEvent mode
      my $cv = AE::cv
      $client-&gt;get_raw( 'bucket_name', 'key_name'
                        sub { do_something_with($_[0]);
                              $cv-&gt;send();
                        }
                  );
      # ... later one
      $cv-&gt;recv();

      # list keys in stream
      $client-&gt;get_keys(foo =&gt; sub{
         my ($key, $done) = @_;

         # you should use another client inside this callback!
         $another_client-&gt;del(foo =&gt; $key);

      });

DESCRIPTION
    Riak::Client is a fast and light Perl client for Riak using PBC
    interface, with optional AnyEvent mode.

    It supports operations like ping, get, exists, put, del, and secondary
    indexes (so-called 2i) setting and querying.

    It has two modes, a traditional procedural mode, and an event based
    mode, using AnyEvent.

    It started as a fork of "Riak::Light" to fix some bugs, but actually
    ended up in a complete rewrite with more features, but the same
    performance.

ATTRIBUTES
  anyevent_mode
    Enables the AnyEvent mode, allowing true asynchronous mode.

  host
    Str, Required. Riak IP or hostname.

  port
    Int, Required. Port of the PBC interface.

  r
    Int, Default 2. R value setting for this client.

  w
    Int, Default 2. W value setting for this client.

  dw
    Int, Default 1. DW value setting for this client.

  connection_timeout
    Float, Default 5. Timeout for connection operation, in seconds. Set to 0
    for no timeout.

  read_timeout
    Float, Default 5. Timeout for read operation, in seconds. Set to 0 for
    no timeout.

  no_delay
    Boolean, Default 0. If set to a true value, TCP_NODELAY will be enabled
    on the socket, which means deactivating Nagle's algorithm. Use only if
    you know what you're doing.

  no_auto_connect
    Bool, Default 0. If set to true, then the module won't automatically
    connect upon instanciation. Instead, you'll have to call "connect()"
    yourself.

  anyevent_mode
    Bool, Default 0. If set to true, then all methods can receive a
    callback, as last argument. If present, the method will return
    immediately, and the callback will be executed upon completion of the
    operation, receiving a condvar as first and only argument. If set to
    false (the default), then the client instance will be synchronous.

METHODS
  connect
      my $client-&gt;connect();

      # or in AnyEvent mode
      $cv = AE::cv;
      $client-&gt;connect(sub { print "connected!\n"; $cv-&gt;send(); });
      $cv-&gt;recv();

    Connects to the Riak server. This is automatically done when "new()" is
    called, unless the "no_auto_connect" attribute is set to true. In
    AnyEvent mode, returns a conditional variable,that will be triggered
    when connected.

  ping
      use Try::Tiny;
      try { $client-&gt;ping() } catch { "oops... something is wrong: $_" };

    Perform a ping operation. Will die in case of error. See "is_alive()"

  is_alive
      $client-&gt;is_alive() or warn "oops... something is wrong: $@";

    Perform a ping operation. Will return false in case of error (which will
    be stored in $@).

  get
      # blocking mode
      my $value = $client-&gt;get(bucket =&gt; 'key');

      # blocking mode, with a callback
      $client-&gt;get(bucket =&gt; 'key', sub { my ($value) = @_; do_stuff($value) });

      # AnyEvent mode, asynchronous
      $cv = AE::cv;
      $client-&gt;get(bucket =&gt; 'key', sub { my ($value) = @_; do_stuff($value); $cv-&gt;send() });
      # ...
      $cv-&gt;recv();

    Perform a fetch operation. Expects bucket and key names. If the
    content_type of the fetched value is 'application/json', automatically
    decodes the JSON into a Perl structure. If you need the raw data you can
    use "get_raw".

  get_raw
      my $scalar_value = $client-&gt;get_raw(bucket =&gt; 'key');

    Perform a fetch operation. Expects bucket and key names. Returns the raw
    data. If you want json to be automatically decoded, you should use
    "get()" instead.

  put
      $client-&gt;put('bucket', 'key', { some_values =&gt; [1,2,3] });
      $client-&gt;put('bucket', 'key', { some_values =&gt; [1,2,3] }, 'application/json);
      $client-&gt;put('bucket', 'key', 'text', 'plain/text');

      # you can set secondary indexes (2i)
      $client-&gt;put( 'bucket', 'key', 'text_value', 'plain/text',
                    { field1_bin =&gt; 'abc', field2_int =&gt; 42 }
                  );
      $client-&gt;put( 'bucket', 'key', { some_values =&gt; [1,2,3] }, undef,
                    { field1_bin =&gt; 'abc', field2_int =&gt; 42 }
                  );

      # you can also set links
      $client-&gt;put( 'bucket', 'key', 'text', 'plain/text', undef,
                    { link_tag1 =&gt; 'bucket/key',
                      link_tag2 =&gt; 'other_bucket/key',
                    }
                  );

      # you can set multiple links for the same tag
      $client-&gt;put( 'bucket', 'key', 'text', 'plain/text', undef,
                    { link_tag1 =&gt; [ qw( bucket/key bucket2/key2 ) ],
                      link_tag2 =&gt; 'other_bucket/key',
                    }
                  );

      # you can also use this form (marginally faster)
      $client-&gt;put( 'bucket', 'key', 'text', 'plain/text', undef,
                    [ { tag =&gt; 'link_tag1', bucket =&gt; 'bucket1', key =&gt; 'key1'},
                      { tag =&gt; 'link_tag2', bucket =&gt; 'bucket2', key =&gt; 'key2'},
                    ],
                  );

    Perform a store operation. Expects bucket and key names, the value, the
    content type (optional, default is 'application/json'), and the indexes
    to set for this value (optional, default is none).

    Will encode the structure in json string if necessary. If you need only
    store the raw data you can use "put_raw" instead.

    IMPORTANT: all the index field names should end by either "_int" or
    "_bin", depending if the index type is integer or binary.

    To query secondary indexes, see "query_index".

  put_raw
      $client-&gt;put_raw('bucket', 'key', encode_json({ some_values =&gt; [1,2,3] }), 'application/json');
      $client-&gt;put_raw('bucket', 'key', 'text');
      $client-&gt;put_raw('bucket', 'key', 'text', undef, {field_bin =&gt; 'foo'});
      $client-&gt;put_raw('bucket', 'key', 'text', undef, {field_bin =&gt; 'foo'}, $links);

    For more example, see "put".

    Perform a store operation. Expects bucket and key names, the value, the
    content type (optional, default is 'plain/text'), the indexes (optional,
    default is none), and links (optional, default is none) to set for this
    value

    This method won't encode the data, but pass it as such, trusting it's in
    the type you've indicated in the passed content-type. If you want the
    structure to be automatically encoded, use "put" instead.

    IMPORTANT: all the index field names should end by either "_int" or
    "_bin", depending if the index type is integer or binary.

    To query secondary indexes, see "query_index".

  del
      $client-&gt;del(bucket =&gt; key);

    Perform a delete operation. Expects bucket and key names.

  get_keys
      # in default mode
      $client-&gt;get_keys(foo =&gt; sub{
         my ($key, $done) = @_;
         # you should use another client inside this callback!
         $another_client-&gt;del(foo =&gt; $key);
      });

      # in anyevent mode
      my $cv = AE::cv;
      $client-&gt;get_keys(foo =&gt; sub{
         my ($key, $done) = @_;
         # ... do stuff with $key
         $done and $cv-&gt;send;
      });
      $cv-&gt;recv();

    WARNING, this method should not be called on a production Riak cluster,
    as it can have a big performance impact. See Riak's documentation.

    WARNING, because Riak doesn't handles pipelining, you cannot use the
    same "Riak::Client" instance inside the callback, it would raise an
    exception.

    Perform a list keys operation. Receive a callback and will call it for
    each key. The callback will receive two arguments: the key, and a
    boolean indicating if it's the last key

    The callback is optional, in which case an ArrayRef of all the keys are
    returned. But don't do that, and always provide a callback, to avoid
    your RAM usage to skyrocket...

  exists
      $client-&gt;exists(bucket =&gt; 'key') or warn "key not found";

    Perform a fetch operation but with head =&gt; 0, and the if there is
    something stored in the bucket/key.

  query_index
    Perform a secondary index (2i) query. Expects a bucket name, the index
    field name, the index value you're searching on, and optionally a
    callback.

    If a callback has been provided, doesn't return anything, but execute
    the callback on each matching keys. callback will receive the key name
    as first argument. key name will also be in $_. If no callback is
    provided, returns and ArrayRef of matching keys.

    The index value you're searching on can be of two types. If it's a
    Scalar, an exact match query will be performed. if the value is an
    ArrayRef, then a range query will be performed, the first element in the
    array will be the range_min, the second element the range_max. other
    elements will be ignored.

    Based on the example in "put", here is how to query it:

      # exact match
      my $matching_keys = $client-&gt;query_index( 'bucket',  'field2_int', 42 ),

      # range match
      my $matching_keys = $client-&gt;query_index( 'bucket',  'field2_int', [ 40, 50] ),

      # range match with callback
      $client-&gt;query_index( 'bucket',  'field2_int', [ 40, 50], sub { print "key : $_" } ),

  get_buckets
    WARNING, this method should not be called on a production Riak cluster,
    as it can have a big performance impact. See Riak's documentation.

  get_bucket_props
  set_bucket_props
  map_reduce
  map_reduce_raw
BENCHMARKS
    Note: These benchmarks are the one provided by "Riak::Light".

    Note: the AnyEvent mode is a bit slower below, because we are forcing
    synchronous mode, even in AnyEvent, so the benchmark is paying the price
    of having AnyEvent enabled but not used.

  GETS
                                      Rate Data::Riak (REST) Riak::Tiny (REST) Net::Riak (REST) Data::Riak::Fast (REST) Net::Riak (PBC) Riak::Client (PBC + AnyEvent) Riak::Light (PBC) Riak::Client (PBC)
      Data::Riak (REST)              427/s                --              -30%             -31%                    -43%            -65%                          -85%              -90%               -91%
      Riak::Tiny (REST)              611/s               43%                --              -2%                    -19%            -51%                          -79%              -86%               -87%
      Net::Riak (REST)               623/s               46%                2%               --                    -17%            -50%                          -78%              -86%               -87%
      Data::Riak::Fast (REST)        755/s               77%               24%              21%                      --            -39%                          -74%              -83%               -84%
      Net::Riak (PBC)               1238/s              190%              103%              99%                     64%              --                          -57%              -72%               -74%
      Riak::Client (PBC + AnyEvent) 2878/s              573%              371%             362%                    281%            132%                            --              -34%               -39%
      Riak::Light (PBC)             4348/s              917%              612%             598%                    476%            251%                           51%                --                -8%
      Riak::Client (PBC)            4706/s             1001%              671%             655%                    524%            280%                           64%                8%                 --

  PUTS
                                      Rate Net::Riak (REST) Data::Riak (REST) Riak::Tiny (REST) Data::Riak::Fast (REST) Net::Riak (PBC) Riak::Light (PBC) Riak::Client (PBC + AnyEvent) Riak::Client (PBC)
      Net::Riak (REST)               542/s               --              -15%              -29%                    -55%            -57%              -90%                          -92%               -92%
      Data::Riak (REST)              635/s              17%                --              -17%                    -47%            -49%              -89%                          -90%               -90%
      Riak::Tiny (REST)              765/s              41%               20%                --                    -36%            -39%              -86%                          -88%               -88%
      Data::Riak::Fast (REST)       1198/s             121%               89%               57%                      --             -4%              -79%                          -82%               -82%
      Net::Riak (PBC)               1254/s             131%               97%               64%                      5%              --              -78%                          -81%               -81%
      Riak::Light (PBC)             5634/s             939%              787%              637%                    370%            349%                --                          -14%               -14%
      Riak::Client (PBC + AnyEvent) 6557/s            1110%              933%              757%                    448%            423%               16%                            --                 0%
      Riak::Client (PBC)            6557/s            1110%              933%              757%                    448%            423%               16%                            0%                 --

SEE ALSO
    Net::Riak

    Data::Riak

    Data::Riak::Fast

    Action::Retry

    Riak::Light

    AnyEvent

CONTRIBUTORS
    Ivan Kruglov &lt;ivan.kruglov@yahoo.com&gt;

AUTHOR
    Damien Krotkine &lt;dams@cpan.org&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2014 by Damien Krotkine.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

</pre></body></html>