Skip to content

Instantly share code, notes, and snippets.

@xconnecting
Created April 2, 2013 08:07
Show Gist options
  • Save xconnecting/5290686 to your computer and use it in GitHub Desktop.
Save xconnecting/5290686 to your computer and use it in GitHub Desktop.
[Groovy] KyotoCabinet Sample
import kyotocabinet.*;
// create the object
DB db = new DB();
// open the database
if (!db.open("casket.kch", DB.OWRITER | DB.OCREATE)){
System.err.println("open error: " + db.error());
}
// store records
if (!db.set("foo", "hop") ||
!db.set("bar", "step") ||
!db.set("baz", "jump")){
System.err.println("set error: " + db.error());
}
// retrieve records
String value = db.get("foo");
if (value != null){
System.out.println(value);
} else {
System.err.println("set error: " + db.error());
}
// traverse records
Cursor cur = db.cursor();
cur.jump();
String[] rec;
while ((rec = cur.get_str(true)) != null) {
System.out.println(rec[0] + ":" + rec[1]);
}
cur.disable();
if(!db.close()){
System.err.println("close error: " + db.error());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment