2.1.0 • Published 9 years ago
shahcache v2.1.0
npm install shahcacheExample
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:
.prefixprefix of dictionary.keySeperatorfor seperatingprefixandidasprefix<keySeperator>id..arraySeperatordefault: ,for seperating array items..redisall redis options
methods
set(id, data<Object|String>)returnsOKlike 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 aftergetand willsetthe hash with last changes. returns a promise.Example
dictionary.get('123').then(dic => { dic.data.new_field = 'new_field'; dic.update() })