RedisWrapper.js 737 B

123456789101112131415161718192021222324
  1. const Settings = require('settings-sharelatex')
  2. const redis = require('redis-sharelatex')
  3. if (
  4. typeof global.beforeEach === 'function' &&
  5. process.argv.join(' ').match(/unit/)
  6. ) {
  7. throw new Error(
  8. 'It looks like unit tests are running, but you are connecting to Redis. Missing a stub?'
  9. )
  10. }
  11. // A per-feature interface to Redis,
  12. // looks up the feature in `settings.redis`
  13. // and returns an appropriate client.
  14. // Necessary because we don't want to migrate web over
  15. // to redis-cluster all at once.
  16. module.exports = {
  17. // feature = 'websessions' | 'ratelimiter' | ...
  18. client(feature) {
  19. const redisFeatureSettings = Settings.redis[feature] || Settings.redis.web
  20. return redis.createClient(redisFeatureSettings)
  21. }
  22. }