shahcache
v2.1.0
Published
creates also returns hashes in a dictionary from redis.
Downloads
10
Maintainers
Readme
npm install shahcache
Example
const shahcache = require('shahcache');
const options = {
prefix: 'online', // Prefix for your dictionary
redis: {
port: 6378
}
}
// create your dictionary object
const online_users = shahcache(options);
let data = {
name: 'Mohammadreza',
family: 'Pahlavi'
}
// Add data to your dictionary (store hash string)
online_users.set('123', data).then(result => {
console.log(result) // OK
}).catch(err) {
throw(err);
}
options
Is an object which:
.prefix
prefix of dictionary.keySeperator
for seperatingprefix
andid
asprefix<keySeperator>id
..arraySeperator
default: ,
for seperating array items..redis
all redis options
methods
set(id, data<Object|String>)
returnsOK
like redis.get(id)
returns an dictionary object.get(id, property)
returns the property from stored hash.Example
// stored hash const user = { name: 'John', family: 'Doe' } user_dictionary.get(id, 'name').then(result => { console.log(result.data.name) // John })
getAll()
returns an object withid
's as keys.delete(id)
redis return style.exists(id)
redis return style.count()
number of stored hashes in dictionary.create(id, data<Object|String>)
returns an object of dictionaryupdate()
should be called afterget
and willset
the hash with last changes. returns a promise.Example
dictionary.get('123').then(dic => { dic.data.new_field = 'new_field'; dic.update() })