2019-05-29 05:21:06 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
2020-11-12 07:52:32 -05:00
|
|
|
const redis = require('@overleaf/redis-wrapper')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2020-02-12 10:13:09 -05:00
|
|
|
if (
|
|
|
|
typeof global.beforeEach === 'function' &&
|
|
|
|
process.argv.join(' ').match(/unit/)
|
|
|
|
) {
|
|
|
|
throw new Error(
|
|
|
|
'It looks like unit tests are running, but you are connecting to Redis. Missing a stub?'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-05-29 05:21:06 -04:00
|
|
|
// A per-feature interface to Redis,
|
|
|
|
// looks up the feature in `settings.redis`
|
|
|
|
// and returns an appropriate client.
|
|
|
|
// Necessary because we don't want to migrate web over
|
|
|
|
// to redis-cluster all at once.
|
2020-02-12 10:13:09 -05:00
|
|
|
module.exports = {
|
2019-05-29 05:21:06 -04:00
|
|
|
// feature = 'websessions' | 'ratelimiter' | ...
|
|
|
|
client(feature) {
|
|
|
|
const redisFeatureSettings = Settings.redis[feature] || Settings.redis.web
|
2020-02-12 10:13:09 -05:00
|
|
|
return redis.createClient(redisFeatureSettings)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|