Skip to content

Commit

Permalink
Adjust REDIS_URL usage in node_redis (#3183)
Browse files Browse the repository at this point in the history
Resolves #2780
  • Loading branch information
Gargron committed May 20, 2017
1 parent ae78d01 commit 20c0054
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/initializers/redis.rb
Expand Up @@ -17,8 +17,9 @@
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
Expand Down
21 changes: 19 additions & 2 deletions streaming/index.js
Expand Up @@ -41,13 +41,30 @@ const dbUrlToConfig = (dbUrl) => {
}

const ssl = params.query && params.query.ssl;

if (ssl) {
config.ssl = ssl === 'true' || ssl === '1';
}

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));
Expand Down Expand Up @@ -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 = {};

Expand Down

0 comments on commit 20c0054

Please sign in to comment.