node-kv
An embeded key-value store for node.js, extremely fast.
Because rocksdb uses a lot of C++11 features, your compiler should support C++11 to compile it.
I test it on:
Windows + VS2013
CentOS 6.5 + gcc 4.8.1
MacOS
If your compiler doesn't support C++11, you can install 0.2.x (without rocksdb) instead.
Features
- Multiple kv engine support. (LMDB / LevelDB / RocksDB).
- High speed. (> 80% speed of c++ version.)
- Compressed bit-vector support, a good choice for bitmap index. (Coming soon.)
- Embeded, easy to use.
Install
npm install node-kv
Test & Benchmark
git clone https://github.com/talrasha007/node-kv.git
npm install
npm install -g matcha mocha
mocha # Run unit test.
matcha # Run benchmark.
Usage
- LMDB
It's a lmdb wrapper, for more information about lmdb, click here & documents
// This example shows how to use lmdb apis.var path = lmdb = lmdb; var env = dir: path mapSize: 8 * 1024 * 1024 // 128M by default maxDbs: 64 // 32 by default; { /* Date type can be: * string * hex - hex string, will convert to binary data equivalent to Buffer(str, 'hex') for storage. * int32 * uint32 * int64 * number * binary - Buffer object */ var db = env; db; console; db; console; db; console; env; // Data will be flushed automatically after 1ms, if you want to query immediately, do this. console;}; { var db = env; var txn = env; db; console; txn; console;}; { var db = env; db; console; console; db; console; console; // Cursor var txn = env cur = db; for var ok = cur; ok; ok = curnext console; console; console; console; console; txn;}; env;
- Cache
// This example shows how to use cache apis.// Cache is used for caching hot data, it is a wrapper of lmdb, it holds 2 lmdb envs(current & old), when current env is full,// it will close old env, set current env as old, and then open a new env as current.var path = cache = cache; var cenv = dir: path cacheSize: 128 * 1024 * 1024 // 256M by default batchSize: 128 // 64 by default; var cdb = cenv; cdb;cdb;cenv; // Data will be flushed automatically after 1ms, if you want to query immediately, do this.console; cdb;;
- LevelDB
Google leveldb wrapper.
var path = lvldb = leveldb; var env = dir: path cacheSize: 256 * 1024 * 1024 // 8MB by default.; var db = env; db;console;db;console; db;db;console;db;console; var cur = db;for var i = cur; i; i = curnext console;
- RocksDB
Facebook rocksdb wrapper.
var path = rocksdb = rocksdb; var env = dir: path cacheSize: 256 * 1024 * 1024 // 4MB by default.; var db = env; env; db;console;db;console; db;db;console;db;console; var cur = db;for var i = cur; i; i = curnext console;