The Riak client for Java.
Java Other
Pull request Compare This branch is 172 commits behind basho:develop.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
riak_pb @ a182694
tools @ e961fc5

Riak Java Client

The Riak Java Client enables communication with Riak, an open source, distributed database that focuses on high availability, horizontal scalability, and predictable latency. Both Riak and this code are maintained by Basho.

The latest version of the Java client supports both Riak KV 2.0+, and Riak TS 1.0+. Please see the Release Notes for more information on specific feature and version support.

  1. Installation
  2. Documentation
  3. Contributing
  4. Roadmap
  5. License and Authors
  6. 2.0 Overview


This branch of the Riak Java Client is for the new v2.0 client, to be used with Riak 2.0.

Previous versions:

riak-client-1.4.4 - For use with Riak 1.4.x

riak-client-1.1.4 - For use with < Riak 1.4.0

This client is published to Maven Central and can be included in your project by adding:


All-in-one jar builds are available here for those that don't want to set up a maven project.


  • Develop: Build Status

Most documentation is living in the wiki. For specifics on our progress here, see the release notes.

Also see the Javadoc site for more in-depth API docs.


riak_pb dependency

To build the Riak Java Client, you must have the correct version of the riak_pb dependency installed to your local Maven repository.

git clone
git checkout
mvn clean install

Security tests

To run the security-related integration tests, you will need to:

1) Setup the certs by running the buildbot makefile's "configure-security-certs" target cd buildbot; make configure-security-certs; cd ../;

2) Copy the certs to your Riak's etc dir, and configure the riak.conf file to use them resources_dir=./src/test/resources riak_etc_dir=/fill/in/this/path/

 # Shell
 cp $resources_dir/cacert.pem $riak_etc_dir
 cp $resources_dir/riak-test-cert.pem $riak_etc_dir
 cp $resources_dir/riakuser-client-cert.pem $riak_etc_dir

 # riak.conf file additions
 ssl.certfile = (riak_etc_dir)/cert.pem
 ssl.keyfile = (riak_etc_dir)/key.pem
 ssl.cacertfile = (riak_etc_dir)/cacert.pem

3) Enable Riak Security riak-admin security enable

4) create a user "riakuser" with the password "riak_cert_user" and configure it with certificate as a source riak-admin security add-user riakuser riak-admin security add-source riakuser certificate

5) create a user "riak_trust_user" with the password "riak_trust_user" and configure it with trust as a source riak-admin security add-user riak_trust_user password=riak_trust_user riak-admin security add-source riak_trust_user trust

6) create a user "riakpass" with the password "riak_passwd_user" and configure it with password as a source riak-admin security add-user riakpass password=Test1234 riak-admin security add-source riakpass password

7) Run the Test suit with the and flags set to true

This repository's maintainers are engineers at Basho and we welcome your contribution to the project! Review the details in in order to give back to this project.

An honest disclaimer

Due to our obsession with stability and our rich ecosystem of users, community updates on this repo may take a little longer to review.

The most helpful way to contribute is by reporting your experience through issues. Issues may not be updated while we review internally, but they're still incredibly appreciated.

Thank you for being part of the community!



License and Authors

The Riak Java Client is Open Source software released under the Apache 2.0 License. Please see the LICENSE file for full license details.


Thank you to all of our contributors! If your name is missing please let us know.

2.0 Overview

Version 2.0 of the Riak Java client is a completely new codebase. It relies on Netty4 in the core for handling network operations and all operations can be executed synchronously or asynchronously.

Getting started with the 2.0 client

The new client is designed to model a Riak cluster:

RJC model

The easiest way to get started with the client is using one of the static methods provided to instantiate and start the client:

RiakClient client =

The RiakClient object is thread safe and may be shared across multiple threads.

For more complex configurations, you can instantiate a RiakCluster from the core packages and supply it to the RiakClient constructor.

RiakNode.Builder builder = new RiakNode.Builder();

List<String> addresses = new LinkedList<String>();

List<RiakNode> nodes = RiakNode.Builder.buildNodes(builder, addresses);
RiakCluster cluster = new RiakCluster.Builder(nodes).build();
RiakClient client = new RiakClient(cluster)

Once you have a client, commands from the com.basho.riak.client.api.commands.* packages are built then executed by the client.

Some basic examples of building and executing these commands is shown below.

Getting Data In

Namespace ns = new Namespace("default", "my_bucket");
Location location = new Location(ns, "my_key");
RiakObject riakObject = new RiakObject();
StoreValue store = new StoreValue.Builder(riakObject)
  .withOption(Option.W, new Quorum(3)).build();

Getting Data Out

Namespace ns = new Namespace("default","my_bucket");
Location location = new Location(ns, "my_key");
FetchValue fv = new FetchValue.Builder(location).build();
FetchValue.Response response = client.execute(fv);
RiakObject obj = response.getValue(RiakObject.class);

Using 2.0 Data Types

A bucket type must be created (in all local and remote clusters) before 2.0 data types can be used. In the example below, it is assumed that the type "my_map_type" has been created and associated to the "my_map_bucket" prior to this code executing.

Once a bucket has been associated with a type, all values stored in that bucket must belong to that data type.

Namespace ns = new Namespace("my_map_type", "my_map_bucket");
Location location = new Location(ns, "my_key");
RegisterUpdate ru1 = new RegisterUpdate(BinaryValue.create("map_value_1"));
RegisterUpdate ru2 = new RegisterUpdate(BinaryValue.create("map_value_2"));
MapUpdate mu = new MapUpdate();
mu.update("map_key_1", ru1);
mu.update("map_key_2", ru2);
UpdateMap update = new UpdateMap.Builder(location, mu).build();

RiakCommand Subclasses

Fetching, storing and deleting objects

Listing keys in a namespace

Secondary index (2i) commands

Fetching and storing datatypes (CRDTs)

Querying and modifying buckets

Search commands