RedisConfig.js
...const setValue = (key, value) => {if (typeof value === 'undefined' || value == null || value === '') {return}if (typeof value === 'string') {client.set(key, value)} else if (typeof value === 'object') {Object.keys(value).forEach((item) => {client.hset(key, item, value[item], redis.print)})}return}const { promisify } = require("util");const getAsync = promisify(client.get).bind(client);const getValue = (key) => {return getAsync(key)}const getHValue = (key) => {return promisify(client.hgetall).bind(client)(key)}export {client,setValue,getValue,getHValue}
test.js
...setValue('imoocobj', {name: 'zbl',email: '95605355@qq.com',age: 30})getHValue('imoocobj').then((res) => {console.log('getHValue:' + JSON.stringify(res))})
