oujRedis.js 502 B

1234567891011121314151617181920212223
  1. var Redis = require('ioredis');
  2. var configs = require('../../conf/config.inc.js');
  3. var oujRedis = {};
  4. var map = {};
  5. /**
  6. * 初始化Redis对象
  7. * @param cacheKey
  8. * @return {Redis}
  9. */
  10. oujRedis.init = function(cacheKey) {
  11. cacheKey = cacheKey || 'default';
  12. if (!map[cacheKey]) {
  13. var redisInfo = configs.redisInfo;
  14. redisInfo[cacheKey]['lazyConnect'] = true;
  15. map[cacheKey] = new Redis(redisInfo[cacheKey]);
  16. }
  17. return map[cacheKey];
  18. }
  19. module.exports = oujRedis;