mirror of https://github.com/Requarks/wiki.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
906 B
37 lines
906 B
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)
|
|
red.on('ready', () => {
|
|
WIKI.logger.info('Redis connection: [ OK ]')
|
|
})
|
|
red.on('error', () => {
|
|
WIKI.logger.error('Failed to connect to Redis instance!')
|
|
process.exit(1)
|
|
})
|
|
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)
|
|
})
|
|
red.subscribe('localization', (err, count) => {
|
|
if (err) {
|
|
WIKI.logger.error(err)
|
|
process.exit(1)
|
|
}
|
|
WIKI.logger.info('Redis Subscriber connection: [ OK ]')
|
|
})
|
|
return red
|
|
}
|
|
}
|