Created
April 2, 2013 08:07
-
-
Save xconnecting/5290686 to your computer and use it in GitHub Desktop.
[Groovy] KyotoCabinet Sample
This file contains 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
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