2017-07-23 03:56:46 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
/* global wiki */
|
|
|
|
|
|
|
|
const Redis = require('ioredis')
|
|
|
|
const { isPlainObject } = require('lodash')
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redis module
|
|
|
|
*
|
|
|
|
* @return {Object} Redis client wrapper instance
|
|
|
|
*/
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize Redis client
|
|
|
|
*
|
|
|
|
* @return {Object} Redis client instance
|
|
|
|
*/
|
|
|
|
init() {
|
|
|
|
if (isPlainObject(wiki.config.redis)) {
|
2017-08-03 03:47:11 +00:00
|
|
|
let red = new Redis(wiki.config.redis)
|
|
|
|
red.on('ready', () => {
|
2017-12-24 05:34:47 +00:00
|
|
|
wiki.logger.info('Redis connection: [ OK ]')
|
2017-08-03 03:47:11 +00:00
|
|
|
})
|
2017-11-13 04:48:19 +00:00
|
|
|
red.on('error', () => {
|
|
|
|
wiki.logger.error('Failed to connect to Redis instance!')
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2017-08-03 03:47:11 +00:00
|
|
|
return red
|
2017-07-23 03:56:46 +00:00
|
|
|
} else {
|
|
|
|
wiki.logger.error('Invalid Redis configuration!')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|