google的levelDB是我很感兴趣并且通读源码的开源项目,因此记录一下源码的阅读过程
levelDB的安装,参考:http://blog.csdn.net/koko2015c/article/details/68066761 ,其实也就是make一下,把动态链接库和API复制到本地,说是一个数据库,实际上说levelDB是库更贴切。
github地址: https://github.com/google/leveldb
测试程序
#include "leveldb/db.h"
#include <cassert>
#include <iostream>
using namespace std;
using namespace leveldb;
int main() {
leveldb::DB *db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "testdb", &db);
assert(status.ok());
status = db->Put(WriteOptions(), "abc", "levelDB here!");
assert(status.ok());
string res;
status = db->Get(ReadOptions(), "abc", &res);
assert(status.ok());
cout << res << endl;
delete db;
return 0;
}