1.0.0 • Published 9 years ago
key-json v1.0.0
key-json :honeybee:
Key/Json Store with multiple interfaces
Install
To install key-json, simply use npm:
npm install key-json --saveExample
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:
loggerLevel: 'info', 'warn', 'error', 'fatal'
instance.use(key, manager)
Set a new manager configuration
key, unique key for the managermanager, 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 secondscb-> (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