连接 redis 使用密码,参考以下
const redis = require('redis')
const { port, host, password } = config
const opt = {}
if (password) {
opt.password = password // prd 环境需要密码
}
const redisClient = redis.createClient(port, host, opt)
redisClient.on('error', err => {
console.error('redis connect error', err)
})
// redisClient.on('connect', () => {
// console.log('redis connect success')
// redisClient.set('foo', 'bar', redis.print) // => "Reply: OK"
// redisClient.get('foo', redis.print) // => "Reply: bar"
// redisClient.quit()
// })
module.exports = redisClient