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.

36 lines
855 B

  1. const Redis = require('ioredis')
  2. const { isPlainObject } = require('lodash')
  3. /* global WIKI */
  4. module.exports = {
  5. init() {
  6. if (isPlainObject(WIKI.config.redis)) {
  7. let red = new Redis(WIKI.config.redis)
  8. red.on('ready', () => {
  9. WIKI.logger.info('Redis connection: [ OK ]')
  10. })
  11. red.on('error', () => {
  12. WIKI.logger.error('Failed to connect to Redis instance!')
  13. process.exit(1)
  14. })
  15. return red
  16. } else {
  17. WIKI.logger.error('Invalid Redis configuration!')
  18. process.exit(1)
  19. }
  20. },
  21. subscribe() {
  22. let red = this.init()
  23. red.on('message', (channel, msg) => {
  24. WIKI.events.emit(channel, msg)
  25. })
  26. red.subscribe('localization', 'updates', (err, count) => {
  27. if (err) {
  28. WIKI.logger.error(err)
  29. process.exit(1)
  30. }
  31. })
  32. return red
  33. }
  34. }