about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-20 21:06:09 +0200
committerGitHub <noreply@github.com>2017-05-20 21:06:09 +0200
commit20c00544600ca35874af7d9d4b2dabf49662a76e (patch)
tree035baa8471cb7984f2b893edd9f65d0c57775b91
parentae78d012acfd245228815f4e404f0cfa15c97f55 (diff)
Adjust REDIS_URL usage in node_redis (#3183)
Resolves #2780
-rw-r--r--config/initializers/redis.rb3
-rw-r--r--streaming/index.js21
2 files changed, 21 insertions, 3 deletions
diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb
index 63fc42557..4ed53ec07 100644
--- a/config/initializers/redis.rb
+++ b/config/initializers/redis.rb
@@ -17,8 +17,9 @@ redis_connection = Redis.new(
 cache_params = { expires_in: 10.minutes }
 
 namespace = ENV.fetch('REDIS_NAMESPACE') { nil }
+
 if namespace
-  Redis.current = Redis::Namespace.new(namespace, :redis => redis_connection)
+  Redis.current = Redis::Namespace.new(namespace, redis: redis_connection)
   cache_params[:namespace] = namespace + '_cache'
 else
   Redis.current = redis_connection
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 = {};