Skip to content

Instantly share code, notes, and snippets.

@aozturk
Last active December 29, 2015 04:19
Show Gist options
  • Save aozturk/7614385 to your computer and use it in GitHub Desktop.
Save aozturk/7614385 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <assert.h>
#include "rocksdb/db.h"
using namespace std;
int main() {
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
// open a database with a name which corresponds to a file system directory
rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db);
// check status
if (!status.ok()) cerr << status.ToString() << endl;
// Slice type can (should) be used in place of std::string for key-value
rocksdb::Slice key = "foo";
std::string value1 = "bar";
// modify/query the database
status = db->Put(rocksdb::WriteOptions(), key, value1);
assert(status.ok());
std::string value2;
status = db->Get(rocksdb::ReadOptions(), key, &value2);
assert(status.ok() && value1 == value2);
status = db->Delete(rocksdb::WriteOptions(), key);
assert(status.ok());
status = db->Get(rocksdb::ReadOptions(), key, &value2);
assert(status.IsNotFound());
// close the database
delete db;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment