summary refs log tree commit diff
path: root/lib/Net/Riak.pm
blob: 61f73aa2fa7faff1c5d70b967fae05639554fe19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package Net::Riak;

# ABSTRACT: Interface to Riak

use Moose;

use Net::Riak::Client;
use Net::Riak::Bucket;
use Net::Riak::Types Client => { -as => 'Client_T' };

with 'Net::Riak::Role::MapReduce';

has client => (
    is       => 'rw',
    isa      => Client_T,
    required => 1,
    handles  => [qw/is_alive all_buckets server_info stats/]
);

sub BUILDARGS {
    my ($class, %args) = @_;

    my $transport = $args{transport} || 'REST';
    my $trait = "Net::Riak::Transport::".$transport;

    my $client = Net::Riak::Client->with_traits($trait)->new(%args);
    $args{client} = $client;
    \%args;
}

sub bucket {
    my ($self, $name) = @_;
    my $bucket = Net::Riak::Bucket->new(name => $name, client => $self->client);
    $bucket;
}

1;

=head1 SYNOPSIS
    
    # REST interface
    my $client = Net::Riak->new(
        host => 'http://10.0.0.40:8098',
        ua_timeout => 900,
        disable_return_body => 1
    );

    # Or PBC interface.
    my $client = Net::Riak->new(
        transport => 'PBC',
        host => '10.0.0.40',
        port => 8080
    );

    my $bucket = $client->bucket('blog');
    my $obj    = $bucket->new_object('new_post', {title => 'foo', content => 'bar'});
    $obj->store;

    $obj = $bucket->get('new_post');
    say "title for ".$obj->key." is ".$obj->data->{title};

=head1 DESCRIPTION

=head2 ATTRIBUTES

=over 2

=item B<host>

REST: The URL of the node

PBC: The hostname of the node

default 'http://127.0.0.1:8098'

Note that providing multiple hosts is now deprecated.

=item B<port>

Port of the PBC interface.

=item B<transport>

Used to select the PB protocol by passing in 'PBC'

=item B<prefix>

Interface prefix (default 'riak')

=item B<mapred_prefix>

MapReduce prefix (default 'mapred')

=item B<r>

R value setting for this client (default 2)

=item B<w>

W value setting for this client (default 2)

=item B<dw>

DW value setting for this client (default 2)

=item B<client_id>

client_id for this client

=item B<ua_timeout (REST only)>

timeout for L<LWP::UserAgent> in seconds, defaults to 3.

=item B<disable_return_body (REST only)>

Disable returning of object content in response in a store operation.

If set  to true and the object has siblings these will not be available without an additional fetch.

This will become the default behaviour in 0.17 

=back

=head1 METHODS

=head2 bucket

    my $bucket = $client->bucket($name);

Get the bucket by the specified name. Since buckets always exist, this will always return a L<Net::Riak::Bucket>

=head2 is_alive

    if (!$client->is_alive) {
        ...
    }

Check if the Riak server for this client is alive

=head2 all_buckets

List all buckets, requires Riak 0.14+ or PBC connection.

=head2 add

    my $map_reduce = $client->add('bucket_name', 'key');

Start assembling a Map/Reduce operation

=head2 link

    my $map_reduce = $client->link();

Start assembling a Map/Reduce operation

=head2 map

    my $map_reduce = $client->add('bucket_name', 'key')->map("function ...");

Start assembling a Map/Reduce operation

=head2 reduce

    my $map_reduce = $client->add(..)->map(..)->reduce("function ...");

Start assembling a Map/Reduce operation

=head2 server_info (PBC only)
    
    $client->server_info->{server_version};

=head2 stats (REST only)

    say Dumper $client->stats;

=head1 SEE ALSO

L<Net::Riak::MapReduce>

L<Net::Riak::Object>

L<Net::Riak::Bucket>

=cut