GithubHelp home page GithubHelp logo

key-json's Introduction

key-json ๐Ÿ

Key/Json Store with multiple interfaces

Install

To install key-json, simply use npm:

npm install key-json --save

Example

const Kj = require('key-json')

const kj = Kj({
	loggerLevel: 'info'
})

kj
//default manager
.use(Kj.managers.redis({
	//redis createClient() configuration
	host: '127.0.0.1',
	port: 6379
}))
.use('memcached', Kj.managers.memcached('localhost:11211', {
	retries:10,
	retry:10000,
	remove:true,
}))
.set('foo', { foo: 'foo' }, (err) => {
})
.get('foo', (err, json) => {
})
.has('foo', (err, exists) => {
})
.delete('foo', (err, done) => {
})
.manager('memcached')
//set bar key in the memcached manager
.set('bar', { bar: 'bar' }, (err) => {
})

Managers

A Manager is an abstraction layer between key-json and storage systems. Currently there are two available managers

  • Redis
  • Memcached

API


Kj([opts])

Creates a new instance of KeyJson.

Options are:

  • loggerLevel: ['info', 'warn', 'error', 'fatal']

instance.use([key, ] manager)

Set a new manager configuration

  • key, unique key for the manager
  • manager, compatible manager interface

instance.manager(key)

Switch to another manager by its key

  • key, unique key for the manager

instance.set(key, json[, expiry, cb])

Store json in its key/value store

  • expiry -> TTL for this key in seconds
  • cb -> (error) => {}

instance.get(key, cb)

Get json by its key

  • cb -> (err, json) => {}, json is already parsed

instance.has(key, cb)

Check if key is stored

  • cb -> (err, exists) => {}, exists is a boolean

instance.delete(key[, cb])

Delete key from the store

  • cb -> (err, done) => {}, done is a boolean

key-json's People

Contributors

daack avatar mauricius avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

mauricius

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.