Permalink
Browse files

Merge pull request #16 from byplayer/add_doc_put_get_method

Add doc put get method
  • Loading branch information...
2 parents b6c211f + 05d7107 commit edf750a7bff20925079f0cefee3e4aed9b6a7f7b @wmorgan committed Mar 8, 2012
Showing with 46 additions and 0 deletions.
  1. +46 −0 ext/leveldb/leveldb.cc
@@ -104,6 +104,26 @@ static leveldb::WriteOptions parse_write_options(VALUE options) {
#define RUBY_STRING_TO_SLICE(x) leveldb::Slice(RSTRING_PTR(x), RSTRING_LEN(x))
#define SLICE_TO_RUBY_STRING(x) rb_str_new(x.data(), x.size())
#define STRING_TO_RUBY_STRING(x) rb_str_new(x.data(), x.size())
+
+/*
+ * call-seq:
+ * get(key, options = nil)
+ *
+ * get data from db
+ *
+ * [key] key you want to get
+ * [options[ :fill_cache ]] Should the data read for this iteration be cached in memory?
+ * Callers may wish to set this field to false for bulk scans.
+ *
+ * true or false
+ *
+ * Default: true
+ * [options[ :verify_checksums ]] If true, all data read from underlying storage will be
+ * verified against corresponding checksums.
+ *
+ * Default: false
+ * [return] value of stored db
+ */
static VALUE db_get(int argc, VALUE* argv, VALUE self) {
VALUE v_key, v_options;
rb_scan_args(argc, argv, "11", &v_key, &v_options);
@@ -157,6 +177,32 @@ static VALUE db_exists(VALUE self, VALUE v_key) {
return Qtrue;
}
+/*
+ * call-seq:
+ * put(key, value, options = nil)
+ *
+ * store data into DB
+ *
+ * [key] key you want to store
+ * [value] data you want to store
+ * [options[ :sync ]] If true, the write will be flushed from the operating system
+ * buffer cache (by calling WritableFile::Sync()) before the write
+ * is considered complete. If this flag is true, writes will be
+ * slower.
+ *
+ * If this flag is false, and the machine crashes, some recent
+ * writes may be lost. Note that if it is just the process that
+ * crashes (i.e., the machine does not reboot), no writes will be
+ * lost even if sync==false.
+ *
+ * In other words, a DB write with sync==false has similar
+ * crash semantics as the "write()" system call. A DB write
+ * with sync==true has similar crash semantics to a "write()"
+ * system call followed by "fsync()".
+ *
+ * Default: false
+ * [return] stored value
+ */
static VALUE db_put(int argc, VALUE* argv, VALUE self) {
VALUE v_key, v_value, v_options;

0 comments on commit edf750a

Please sign in to comment.