Socket
Book a DemoInstallSign in
Socket

fib-kv

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fib-kv

general key-value store on sql/level/mongo/redis for fibjs

1.6.0
latest
Source
npmnpm
Version published
Weekly downloads
11
-54.17%
Maintainers
3
Weekly downloads
 
Created
Source

fib-kv

NPM version Build Status Build status

Introduction

general key-value store on sql/level/mongo/redis for fibjs.

Install

npm install fib-kv [--save]

Test

npm run ci

Creating a key-value store

var kvs = new kv(conn, opts);

conn: database connection or connection factory like fib-pool
opts: kvs options
optsdefaultobject/MapLruCacheLevelDBRedisMongoDBSQLite/MySQL
table_name"kvs"xxx
key_name"k"xxxx
value_name"v"xxxx
key_size32xxxxx
value_size256xxxxx
cleanup_interval(ms)60000xxxxx
timeout(ms)0xx
prefix""
cachefalse
cache_size65536
cache_timeout(ms)60000
sql_value_type60000xxxxx

NOTICE sql_value_type is one of below:

  • TINYBLOB
  • BLOB
  • MEDIUMBLOB
  • LONGBLOB
  • TINYTEXT
  • TEXT
  • MEDIUMTEXT
  • LONGTEXT
  • VARCHAR

A key will not expire if timeout is less than or equal to 0.

Simple example (memory backend).

var kv = require("fib-kv");

var kvs = new kv({
    "a": 100,
    "b": 200
});

LevelDB backend.

var kv = require("fib-kv");
var db = require("db");

var kvs = new kv(db.openLevelDB("test.ldb"));

fib-pool backend.

var kv = require("fib-kv");
var db = require("db");
var pool = require("fib-pool");

var kvs = new kv(pool(() => db.openLevelDB("test.ldb")));

Methods

kvs.setup()

setup the backend database.

v = kvs.get(k)

returns the value stored for that key.

kvs.set(k, v)

stores a key-value pair.

e = kvs.has(k)

returns whether a key is set on the store.

e = kvs.keys()

returns all keys in the store.

e = kvs.renew(k)

renews TTL for an unexpired key.

kvs.remove(k)

deletes a key-value pair by key.

e = kvs.cache_has(k)

returns whether a key is set on the cache.

kvs.cache_clear()

removes all the key-value pairs in the cache.

Keywords

key

FAQs

Package last updated on 18 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.