Created
June 20, 2013 17:51
-
-
Save angrycub/5824975 to your computer and use it in GitHub Desktop.
Using the Riak Java Client 1.1.1 over Protocol Buffers to retrieve the "HEAD" of a Riak Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package basho; | |
import com.basho.riak.client.IRiakClient; | |
import com.basho.riak.client.IRiakObject; | |
import com.basho.riak.client.RiakFactory; | |
import com.basho.riak.client.bucket.Bucket; | |
import com.basho.riak.client.convert.RiakKey; | |
public class App | |
{ | |
public static class SimpleObject | |
{ | |
@RiakKey private String key; | |
private String value; | |
public SimpleObject() {} | |
public SimpleObject(String key, String value){this.key = key; this.setValue(value);} | |
public String getValue() {return value;} | |
public String getKey() {return key;} | |
public void setValue(String value) {this.value = value;} | |
} | |
public static void main( String[] args ) throws Exception { | |
String riakServerIp = "127.0.0.1"; | |
int pbPort = 10017; | |
String bucket = "Test"; | |
String key = "test"; | |
SimpleObject myNewObject = new SimpleObject(key,"sample value"); | |
IRiakClient myDefaultPBClient = RiakFactory.pbcClient(riakServerIp, pbPort); | |
Bucket b = myDefaultPBClient.createBucket(bucket).allowSiblings(true).execute(); | |
b.store(myNewObject).execute(); | |
IRiakObject myObjectHead = b.fetch(key).headOnly().execute(); | |
System.out.println(myObjectHead.getValueAsString()); | |
IRiakObject myObject = b.fetch(key).execute(); | |
System.out.println(myObject.getValueAsString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment