npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kv-node

v0.4.6

Published

An embeded key-value store for node.js, extremely fast.

Downloads

20

Readme

#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 = require('path'),
    lmdb = require('node-kv').lmdb;

var env = new lmdb.Env({
    dir: path.join(__dirname, 'testdb'),
    mapSize: 8 * 1024 * 1024, // 128M by default
    maxDbs: 64 // 32 by default
});

(function () {
    /* 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.openDb({
        name: 'test',
        keyType: 'int32',
        valType: 'int32' // or valveType
    });

    db.put(1, 1);
    console.log(db.get(1));
    db.del(1);
    console.log(db.get(1));

    db.batchPut(6, 6);
    console.log(db.get(6));
    env.flushBatchOps(); // Data will be flushed automatically after 1ms, if you want to query immediately, do this.
    console.log(db.get(6));
})();

(function () {
    var db = env.openDb({
        name: 'str-test',
        keyType: 'string',
        valType: 'string' // or valveType
    });

    var txn = env.beginTxn();
    db.put('Hello', 'world', txn);
    console.log(db.get('Hello', txn));
    txn.abort();
    console.log(db.get('Hello'));
})();

(function () {
    var db = env.openDb({
        name: 'testdup',
        keyType: 'int32',
        valType: 'int32',
        allowDup: true
    });

    db.put(1, 1);
    console.log(db.exists(1, 1));
    console.log(db.exists(1, 2));
    db.put(1, 2);
    console.log(db.exists(1, 1));
    console.log(db.exists(1, 2));

    // Cursor
    var txn = env.beginTxn(true),
        cur = db.cursor(txn);

    for (var ok = cur.first(); ok; ok = cur.next()) {
        console.log("Cursor scan: ", cur.key(), cur.val());
    }

    console.log(cur.seek(1));
    console.log(cur.key(), cur.val());
    console.log(cur.gte(0));
    console.log(cur.key(), cur.val());

    txn.abort();
})();

env.close();

- 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 = require('path'),
    cache = require('node-kv').cache;

var cenv = new cache.Env({
    dir: path.join(__dirname, 'testdb', 'cache'),
    cacheSize: 128 * 1024 * 1024,   // 256M by default
    batchSize: 128                  // 64 by default
});

var cdb = cenv.openDb({
    name: 'testdb',
    keyType: 'int32',
    valType: 'int32'
});

cdb.put(1, 2);
cdb.put(2, 3);
cenv.flushBatchOps(); // Data will be flushed automatically after 1ms, if you want to query immediately, do this.
console.log(cdb.get(1));

cdb.put(3, 3);
setTimeout(function () {
    console.log(cdb.get(3));
    cenv.close();
}, 50);

- LevelDB

Google leveldb wrapper.

var path = require('path'),
    lvldb = require('node-kv').leveldb;

var env = new lvldb.Env({
    dir: path.join(__dirname, 'testdb', 'level'),
    cacheSize: 256 * 1024 * 1024 // 8MB by default.
});

var db = env.openDb({
    name: 'test',
    keyType: 'int32',
    valType: 'int32'
});

db.put(1, 1);
console.log(db.get(1));
db.del(1);
console.log(db.get(1));

db.del(3);
db.batchPut(3, 4);
console.log(db.get(3));
db.flushBatchOps();
console.log(db.get(3));

var cur = db.cursor();
for (var i = cur.first(); i; i = cur.next()) {
    console.log([cur.key(), cur.val()]);
}

- RocksDB

Facebook rocksdb wrapper.

var path = require('path'),
    rocksdb = require('node-kv').rocksdb;

var env = new rocksdb.Env({
    dir: path.join(__dirname, 'testdb', 'rocks'),
    cacheSize: 256 * 1024 * 1024 // 4MB by default.
});

var db = env.registerDb({
    name: 'test',
    keyType: 'int32',
    valType: 'int32'
});

env.open();

db.put(1, 1);
console.log(db.get(1));
db.del(1);
console.log(db.get(1));

db.del(3);
db.batchPut(3, 4);
console.log(db.get(3));
db.flushBatchOps();
console.log(db.get(3));

var cur = db.cursor();
for (var i = cur.first(); i; i = cur.next()) {
    console.log([cur.key(), cur.val()]);
}