You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alex Moore edited this page Jun 24, 2015
·
1 revision
Note: This document is for the 2.x Java Client series.
Creating or modifying a bucket in Riak
importcom.basho.riak.client.api.RiakClient;
importcom.basho.riak.client.api.commands.buckets.FetchBucketProperties;
importcom.basho.riak.client.api.commands.buckets.StoreBucketProperties;
importcom.basho.riak.client.core.operations.FetchBucketPropsOperation;
importcom.basho.riak.client.core.query.BucketProperties;
importcom.basho.riak.client.core.query.Namespace;
importjava.net.UnknownHostException;
importjava.util.concurrent.ExecutionException;
publicclassBucketTypeProperties
{
publicstaticvoidmain(String [] args) throwsUnknownHostException, ExecutionException, InterruptedException {
RiakClientclient = RiakClient.newClient(10017, "127.0.0.1");
Namespacens = newNamespace("TestBucket");
// If the bucket does not exist in Riak, it will be created with the default properties when you query for them. FetchBucketPropertiesfetchProps = newFetchBucketProperties.Builder(ns).build();
FetchBucketPropsOperation.ResponsefetchResponse = client.execute(fetchProps);
BucketPropertiesbp = fetchResponse.getBucketProperties();
// By using the StoreBucketProperties command, // you can specify properties' values. //// If the bucket already exists in Riak, the bucket // properties will be updated.//// Only those properties that you specify will be updated, // there is no need to fetch the bucket properties to edit them.StoreBucketPropertiesstoreProps =
newStoreBucketProperties.Builder(ns)
.withNVal(2).withR(1).build();
client.execute(storeProps);
client.shutdown();
}
}