wikijs-fork/server/core/redis.js

37 lines
855 B
JavaScript
Raw Normal View History

const Redis = require('ioredis')
const { isPlainObject } = require('lodash')
/* global WIKI */
module.exports = {
init() {
if (isPlainObject(WIKI.config.redis)) {
let red = new Redis(WIKI.config.redis)
2017-08-03 03:47:11 +00:00
red.on('ready', () => {
WIKI.logger.info('Redis connection: [ OK ]')
2017-08-03 03:47:11 +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
} else {
WIKI.logger.error('Invalid Redis configuration!')
process.exit(1)
}
},
subscribe() {
let red = this.init()
red.on('message', (channel, msg) => {
WIKI.events.emit(channel, msg)
})
2019-01-13 20:37:45 +00:00
red.subscribe('localization', 'updates', (err, count) => {
if (err) {
WIKI.logger.error(err)
process.exit(1)
}
})
return red
}
}