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