UNPKG

redis-store-json

Version:

Light package for easily getting and storing json object on redis database

29 lines (19 loc) 719 B
const {promisify} = require('util'); const getInformationByKey = (redis, key) =>{ return new Promise((resolve, reject) => { const getAsync = promisify(redis.get).bind(redis); getAsync(key) .then(data => { try{ let parsed = JSON.parse(data); resolve(parsed) }catch(e) { reject('[redis-store-JSON] value stored are not json') } }) .catch(err => { reject(`[redis-store-JSON] no redis key found for ${key}`) }) }) } module.exports = getInformationByKey;