| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Riak; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Net::Riak::VERSION = '0.1702'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Interface to Riak |
|
7
|
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
513943
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Net::Riak::Client; |
|
11
|
|
|
|
|
|
|
use Net::Riak::Bucket; |
|
12
|
|
|
|
|
|
|
use Net::Riak::Types Client => { -as => 'Client_T' }; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Net::Riak::Role::MapReduce'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has client => ( |
|
17
|
|
|
|
|
|
|
is => 'rw', |
|
18
|
|
|
|
|
|
|
isa => Client_T, |
|
19
|
|
|
|
|
|
|
required => 1, |
|
20
|
|
|
|
|
|
|
handles => [qw/is_alive all_buckets server_info stats search index setup_indexing/] |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub BUILDARGS { |
|
24
|
|
|
|
|
|
|
my ($class, %args) = @_; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $transport = $args{transport} || 'REST'; |
|
27
|
|
|
|
|
|
|
my $trait = "Net::Riak::Transport::".$transport; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $client = Net::Riak::Client->with_traits($trait)->new(%args); |
|
30
|
|
|
|
|
|
|
$args{client} = $client; |
|
31
|
|
|
|
|
|
|
\%args; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub bucket { |
|
35
|
|
|
|
|
|
|
my ($self, $name) = @_; |
|
36
|
|
|
|
|
|
|
my $bucket = Net::Riak::Bucket->new(name => $name, client => $self->client); |
|
37
|
|
|
|
|
|
|
$bucket; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=pod |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Net::Riak - Interface to Riak |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 VERSION |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
version 0.1702 |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# REST interface |
|
57
|
|
|
|
|
|
|
my $client = Net::Riak->new( |
|
58
|
|
|
|
|
|
|
host => 'http://10.0.0.40:8098', |
|
59
|
|
|
|
|
|
|
ua_timeout => 900, |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Or PBC interface. |
|
63
|
|
|
|
|
|
|
my $client = Net::Riak->new( |
|
64
|
|
|
|
|
|
|
transport => 'PBC', |
|
65
|
|
|
|
|
|
|
host => '10.0.0.40', |
|
66
|
|
|
|
|
|
|
port => 8080 |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $bucket = $client->bucket('blog'); |
|
70
|
|
|
|
|
|
|
my $obj = $bucket->new_object('new_post', {title => 'foo', content => 'bar'}); |
|
71
|
|
|
|
|
|
|
$obj->store; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$obj = $bucket->get('new_post'); |
|
74
|
|
|
|
|
|
|
say "title for ".$obj->key." is ".$obj->data->{title}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Indexing and searching (REST interface) |
|
77
|
|
|
|
|
|
|
$client->setup_indexing("bucket_name"); |
|
78
|
|
|
|
|
|
|
...adding documents to riak... |
|
79
|
|
|
|
|
|
|
my $response = $client->search( |
|
80
|
|
|
|
|
|
|
index => 'bucket_name', |
|
81
|
|
|
|
|
|
|
q => 'field:value' |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Secondary index setup (REST interface) |
|
85
|
|
|
|
|
|
|
my $obj3 = $bucket->new_object('foo3', {...}); |
|
86
|
|
|
|
|
|
|
$obj3->add_index('myindex_bin','myvalue' ); |
|
87
|
|
|
|
|
|
|
$obj3->add_index('number_int', 1001); |
|
88
|
|
|
|
|
|
|
$obj3->store; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Get all keys for a specific index/value pair |
|
91
|
|
|
|
|
|
|
my @keys = $client->index('mybucket', 'myindex_bin', 'myvalue' ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Get all keys for a range of index value pairs |
|
94
|
|
|
|
|
|
|
my @keys = $client->index('mybucket', 'number_int', 500, 1500); |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Removing a secondary index (REST interface) |
|
97
|
|
|
|
|
|
|
my $new_obj = $bucket->get('foo3'); |
|
98
|
|
|
|
|
|
|
$new_obj->remove_index('number_int', 1001); |
|
99
|
|
|
|
|
|
|
$new_obj->store; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=over 2 |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item B<host> |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
REST: The URL of the node |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
PBC: The hostname of the node |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
default 'http://127.0.0.1:8098' |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Note that providing multiple hosts is now deprecated. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item B<port> |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Port of the PBC interface. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B<transport> |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Used to select the PB protocol by passing in 'PBC' |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item B<prefix> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Interface prefix (default 'riak') |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item B<mapred_prefix> |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
MapReduce prefix (default 'mapred') |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B<r> |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
R value setting for this client (default 2) |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B<w> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
W value setting for this client (default 2) |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item B<dw> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
DW value setting for this client (default 2) |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item B<client_id> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
client_id for this client |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item B<ua_timeout (REST only)> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
timeout for L<LWP::UserAgent> in seconds, defaults to 3. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item B<disable_return_body (REST only)> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Disable returning of object content in response in a store operation. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
If set to true and the object has siblings these will not be available without an additional fetch. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This will become the default behaviour in 0.17 |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 METHODS |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 bucket |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
my $bucket = $client->bucket($name); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Get the bucket by the specified name. Since buckets always exist, this will always return a L<Net::Riak::Bucket> |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 is_alive |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
if (!$client->is_alive) { |
|
174
|
|
|
|
|
|
|
... |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Check if the Riak server for this client is alive |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 all_buckets |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
List all buckets, requires Riak 0.14+ or PBC connection. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 add |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $map_reduce = $client->add('bucket_name', 'key'); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Start assembling a Map/Reduce operation |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 link |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
my $map_reduce = $client->link(); |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Start assembling a Map/Reduce operation |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 map |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $map_reduce = $client->add('bucket_name', 'key')->map("function ..."); |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Start assembling a Map/Reduce operation |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 reduce |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my $map_reduce = $client->add(..)->map(..)->reduce("function ..."); |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Start assembling a Map/Reduce operation |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 server_info (PBC only) |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$client->server_info->{server_version}; |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 stats (REST only) |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
say Dumper $client->stats; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 search (REST only) |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$client->search( index => 'bucket_name', q => 'field:value' ); |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Makes a query to the index (see L<Net::Riak::Search> for more details on parameters) |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 setup_indexing (REST only) |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
$client->setup_indexing('bucket_name'); |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Define precommit hook in order to enable indexing documents written into the given bucket |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
L<Net::Riak::MapReduce> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
L<Net::Riak::Object> |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L<Net::Riak::Bucket> |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHOR |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This software is copyright (c) 2013 by linkfluence. |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
244
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |