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
750 B

  1. 'use strict'
  2. /* global wiki */
  3. const Redis = require('ioredis')
  4. const { isPlainObject } = require('lodash')
  5. /**
  6. * Redis module
  7. *
  8. * @return {Object} Redis client wrapper instance
  9. */
  10. module.exports = {
  11. /**
  12. * Initialize Redis client
  13. *
  14. * @return {Object} Redis client instance
  15. */
  16. init() {
  17. if (isPlainObject(wiki.config.redis)) {
  18. let red = new Redis(wiki.config.redis)
  19. red.on('ready', () => {
  20. wiki.logger.info('Redis connection: [ OK ]')
  21. })
  22. red.on('error', () => {
  23. wiki.logger.error('Failed to connect to Redis instance!')
  24. process.exit(1)
  25. })
  26. return red
  27. } else {
  28. wiki.logger.error('Invalid Redis configuration!')
  29. process.exit(1)
  30. }
  31. }
  32. }