var Redis = require('ioredis'); //导入 安装好的 redis. npm i ioredis --save var config = require('../config/config.js') // 导入位置文件 //redis 服务启动 /usr/local/bin/redis-server /usr/local/etc/redis.conf var REDIS_INSTANCE = new Redis({ port: config.db_config.test.redis.PORT, host: config.db_config.test.redis.HOST, username: config.db_config.test.redis.USERNAME, password: config.db_config.test.redis.PASSWORD, }); function redis_set(key,value){ REDIS_INSTANCE.set(key,value); } async function redis_get(key){ return await REDIS_INSTANCE.get(key); } module.exports = { redis_set, redis_get, }