You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
788 B

3 years ago
'use strict';
3 years ago
// https://github.com/luin/ioredis
3 years ago
const redis = require("ioredis")
module.exports = async function factory (app, opts) {
3 years ago
let client = new redis(opts.redis.port, opts.redis.host);
3 years ago
3 years ago
client.on("error", function (err) {
app.fs.logger.error('info', '[FS-AUTH-REDIS]', `redis connect error. ${opts.redis.host + ':' + opts.redis.port}` );
// console.error("Error :", err);
// process.exit(-1);
});
3 years ago
3 years ago
client.on('connect', function () {
console.info(`redis connect success ${opts.redis.host + ':' + opts.redis.port}`);
})
3 years ago
3 years ago
// 自定义方法
async function hdelall (key) {
const obj = await client.hgetall(key);
await client.hdel(key, Object.keys(obj))
}
3 years ago
3 years ago
app.redis = client
app.redisTools = {
hdelall,
}
3 years ago
}