1.0.0 • Published 7 years ago

key-json v1.0.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

key-json :honeybee:

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()
  • instance.use()
  • instance.manager()
  • instance.set()
  • instance.get()
  • instance.has()
  • instance.delete()

Kj(opts)

Creates a new instance of KeyJson.

Options are:


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
1.0.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago