1234567891011121314151617181920212223242526272829303132333435363738 |
- "use strict";
- var Redis = require('ioredis');
- var configs = require('../../conf/config.inc.js');
- var map = {};
- class OujRedis {
- /**
- * 初始化Redis对象
- * @param cacheKey
- * @return {Redis}
- */
- static init(cacheKey) {
- cacheKey = cacheKey || 'default';
- let objRedis = map[cacheKey];
- if (!objRedis || !objRedis.connecting) {
- map[cacheKey] = this.initNewOne(cacheKey);
- }
- return map[cacheKey];
- }
- /**
- * 初始化新的实例子
- * @param cacheKey
- *
- * @return Redis
- */
- static initNewOne(cacheKey) {
- let redisInfo = configs.redisInfo;
- redisInfo[cacheKey]['lazyConnect'] = true;
- return new Redis(redisInfo[cacheKey]);
- }
- }
- module.exports = OujRedis;
|