Key/Json Store with multiple interfaces
To install key-json, simply use npm:
npm install key-json --save
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) => {
})
A Manager is an abstraction layer between key-json and storage systems. Currently there are two available managers
- Redis
- Memcached
Kj()
instance.use()
instance.manager()
instance.set()
instance.get()
instance.has()
instance.delete()
Creates a new instance of KeyJson.
Options are:
loggerLevel
: ['info', 'warn', 'error', 'fatal']
Set a new manager configuration
key
, unique key for the managermanager
, compatible manager interface
Switch to another manager by its key
key
, unique key for the manager
Store json in its key/value store
expiry
-> TTL for this key in secondscb
-> (error) => {}
Get json by its key
cb
-> (err, json) => {}, json is already parsed
Check if key is stored
cb
-> (err, exists) => {}, exists is a boolean
Delete key from the store
cb
-> (err, done) => {}, done is a boolean