Hi,

Following up on this question, is there a way to list (not multi-fetch, just list) the existing counters in a bucket?

Regards,

Guido.

On 24/01/14 22:01, Dave Rusek wrote:
Guido,

I’m sorry, there are not currently any docs available. Rest assured they are a work in progress. In the meantime, please feel free to check-out the current pre-release [1]. The pre-release covers the low level API we have built on top of the PB interface. There is a start to a friendlier API in the develop branch of riak-java-client [2].

If you would like to get started with the low level API to begin getting a feel for Riak datatypes, I have included a few snippets that will hopefully help. The counters (and the data structures in general) are implemented as two separate operations: Fetch and Update. Updating a counter that does not exist will create it and initialize it to the given value. Fetching a counter that has not had a value stored will return an empty value.

While the low level API does not have convenience methods for getAndIncrement and the like, they can all be easily accomplished given fetch and update. It would clearly be easy for us to provide methods for these typical access patterns and in fact, it is something we are planning on doing.

RiakCluster cluster = …
BinaryValue bucket = …
BinaryValue key = …
BinaryValue type = ...

fetch():

DtFetchOperation get =
new DtFetchOperation.Builder(bucket, key)
.withBucketType(type)
.build();

DtFetchOperation.Response response = cluster.execute(get).get();

long value;
CrdtElement element = response.getCrdtElement();
if (crdtElement.isCounter()) {
value = element.getCounter().getValue();
} else {
...
}

update():

DtUpdateOperation update =
new DtUpdateOperation.Builder(bucket, key)
.withBucketType(type)
.withReturnBody(true)
.withOp(new CounterOp(1)) // increment by 1
.build();

DtUpdateOperation.Response response = cluster.execute(update).get();

long value;
CrdtElement element = response.getCrdtElement();
if (crdtElement.isCounter()) {
value = element.getCounter().getValue();
} else {
...
}

getAndIncrement();

long value = fetch();
update(1);

incrementAndGet():

long value = update(1); // make sure withReturnBody == true

[1] https://github.com/basho/riak-java-client
[2]https://github.com/basho/riak-java-client/tree/develop/src/main/java/com/basho/riak/client/operations

--
Dave Rusek
Basho Technologies
@davidjrusek

On January 24, 2014 at 8:41:07 AM, Guido Medina ([email protected] <mailto://[email protected]>) wrote:

Hi,

Is there any small doc that could explain its usage a little bit:

From the Java perspective it would be nice if it point out its counter part methods with Atomic Integer like:

  * How to create it? Does incrementing a counter will just create it
    with zero as initial value and then increment it? What if you
    need to know its value and then increment it before it is
    created? (getAndIncrement)
  * get()
  * getAndIncrement()
  * incrementAndGet()

Regards,

Guido.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to