2016-12-19 07:17:02 -05:00
|
|
|
Settings = require 'settings-sharelatex'
|
|
|
|
redis = require 'redis-sharelatex'
|
|
|
|
ioredis = require 'ioredis'
|
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
# TODO: consider merging into `redis-sharelatex`
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Redis =
|
|
|
|
|
|
|
|
# feature = 'websessions' | 'ratelimiter' | ...
|
|
|
|
client: (feature) ->
|
|
|
|
redisFeatureSettings = Settings.redis[feature] or Settings.redis.web
|
|
|
|
if redisFeatureSettings?.cluster?
|
|
|
|
logger.log {feature}, "creating redis-cluster client"
|
|
|
|
rclient = new ioredis.Cluster(redisFeatureSettings.cluster)
|
2016-12-19 10:12:22 -05:00
|
|
|
rclient.__is_redis_cluster = true
|
2016-12-19 07:17:02 -05:00
|
|
|
else
|
|
|
|
logger.log {feature}, "creating redis client"
|
|
|
|
rclient = redis.createClient(redisFeatureSettings)
|
|
|
|
return rclient
|