Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (50 sloc) 2.557 kb
75d2714 @krestenkrab Minor cleanups; add README
authored
1 ## Java Client API for Riak based on the Protocol Buffers API
2
3 This is an alternative to
4 (riak-java-client)[http://hg.basho.com/riak-java-client/] which offers
5 significantly better performance because you avoid encoding and decoding
6 content into the HTTP protocol.
7
8
9 RiakClient riak = new RiakClient("127.0.0.1");
10 byte[] data = new byte[] { 1, 2, 3, 4 };
11 RiakObject ro = new RiakObject("Bucket", "Key",
12 ByteString.copyFrom(data));
13 riak.store(ro);
14
15 Some of the API uses `com.google.protobuf.ByteString` which represents a
16 chunk of (uninterpreted) bytes.
17
18 Here is a complete program to list the entire contents of a riak
19 store.
20
21 RiakClient client = new RiakClient("127.0.0.1");
22 ByteString[] buckets = client.listBuckets();
23 for (ByteString bucket : buckets) {
24 System.out.println("=bucket "+bucket.toStringUtf8());
25 KeySource keys = client.listKeys(bucket);
26 for (ByteString key : keys) {
27 System.out.println("==key "+key.toStringUtf8());
28 RiakObject[] ros = client.fetch(bucket, key);
29 for (RiakObject ro : ros) {
30 System.out.println("==="+ro.toString());
31 }
32 }
33 keys.close();
34 }
35
36 The methods `RiakClient.listKeys` and `RiakClient.mapReduce` return
37 streaming handlers that should be closed when done.
38
39 If you set a clientID `RiakClient.setClientID`; that client ID is used
40 for all connections coming from the same client. `RiakClient` is
41 "thread safe" so you can use it from several threads at the same time.
42
43 ### Bulk Insert
44
45 The method `RiakClient.store(RiakObject[], RequestMeta)` allows
46 efficient bulk insertion (connection request/responses are handled
47 asynchroneously underneath the covers). To run even faster, you can
48 choose to run this in several threads (resulting in multiple connections).
49
50
51 ## License / Copyright
52
53 A Java Client API for Riak based on the Protocol Buffers API
54
55 Copyright (C) 2010 Trifork A/S
56
57 Licensed under the Apache License, Version 2.0 (the "License");
58 you may not use this file except in compliance with the License.
59 You may obtain a copy of the License at
60
61 http://www.apache.org/licenses/LICENSE-2.0
62
63 Unless required by applicable law or agreed to in writing, software
64 distributed under the License is distributed on an "AS IS" BASIS,
65 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66 See the License for the specific language governing permissions and
67 limitations under the License.
Something went wrong with that request. Please try again.