From 20c00544600ca35874af7d9d4b2dabf49662a76e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 20 May 2017 21:06:09 +0200 Subject: Adjust REDIS_URL usage in node_redis (#3183) Resolves #2780 --- streaming/index.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'streaming') diff --git a/streaming/index.js b/streaming/index.js index cd1963121..b020d59fc 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -41,6 +41,7 @@ const dbUrlToConfig = (dbUrl) => { } const ssl = params.query && params.query.ssl; + if (ssl) { config.ssl = ssl === 'true' || ssl === '1'; } @@ -48,6 +49,22 @@ const dbUrlToConfig = (dbUrl) => { return config; }; +const redisUrlToClient = (defaultConfig, redisUrl) => { + const config = defaultConfig; + + if (!redisUrl) { + return redis.createClient(config); + } + + if (redisUrl.startsWith('unix://')) { + return redis.createClient(redisUrl.slice(7), config); + } + + return redis.createClient(Object.assign(config, { + url: redisUrl, + })); +}; + if (cluster.isMaster) { // Cluster master const core = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : Math.max(os.cpus().length - 1, 1)); @@ -94,15 +111,15 @@ if (cluster.isMaster) { port: process.env.REDIS_PORT || 6379, db: process.env.REDIS_DB || 0, password: process.env.REDIS_PASSWORD, - url: process.env.REDIS_URL || null, }; if (redisNamespace) { redisParams.namespace = redisNamespace; } + const redisPrefix = redisNamespace ? `${redisNamespace}:` : ''; - const redisClient = redis.createClient(redisParams); + const redisClient = redisUrlToClient(redisParams, process.env.REDIS_URL); const subs = {}; -- cgit