标签:
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options,"/tmp/testdb",&db);
assert(status.ok());
status = db->put(leveldb::WriteOptions(),"name","phgame");
assert(status.ok());
status = db->get(leveldb::ReadOptions(),"name",&value);
assert(status.ok());
leveldb::ReadOptions readoptions;
readoptions.snapshot = db->getSnapshot();
leveldb::Iterator* itor = db->NewIterator(readoptions);
for(iter->SeekToFirst();iter->Valid();iter->Next()){
std::out<<iter->key().ToString()<<" :" <<iter->value().ToString();
db->ReleaseSnapshot(readoptions.snapshot);
delete db;
上面的代码包含了基本用法,包括打开,关闭,写入,读出,snapshot,iterator,等基本操作,可以看到google的命名规则.
Google C++ Style Guide
http://www.cnblogs.com/chlyzone/archive/2011/04/09/2010455.html
leveldb是根据big table的思想来做的,所以咱们还需要理解一下bigtable是怎么回事,当然我也不懂..慢慢来吧
标签:
原文地址:http://blog.csdn.net/shcalm/article/details/43567519