redis.js 382 B

123456789101112131415161718192021
  1. const redis = require('redis')
  2. let redisClient
  3. /**
  4. * A Singleton module that provides only on redis client through out
  5. * the lifetime of the server
  6. *
  7. * @param {object=} opts node-redis client options
  8. */
  9. module.exports.client = (opts) => {
  10. if (!opts) {
  11. return redisClient
  12. }
  13. if (!redisClient) {
  14. redisClient = redis.createClient(opts)
  15. }
  16. return redisClient
  17. }