parent
							
								
									ae78d012ac
								
							
						
					
					
						commit
						20c0054460
					
				
					 2 changed files with 21 additions and 3 deletions
				
			
		| 
						 | 
					@ -17,8 +17,9 @@ redis_connection = Redis.new(
 | 
				
			||||||
cache_params = { expires_in: 10.minutes }
 | 
					cache_params = { expires_in: 10.minutes }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace = ENV.fetch('REDIS_NAMESPACE') { nil }
 | 
					namespace = ENV.fetch('REDIS_NAMESPACE') { nil }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if namespace
 | 
					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'
 | 
					  cache_params[:namespace] = namespace + '_cache'
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
  Redis.current = redis_connection
 | 
					  Redis.current = redis_connection
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,7 @@ const dbUrlToConfig = (dbUrl) => {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const ssl = params.query && params.query.ssl;
 | 
					  const ssl = params.query && params.query.ssl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (ssl) {
 | 
					  if (ssl) {
 | 
				
			||||||
    config.ssl = ssl === 'true' || ssl === '1';
 | 
					    config.ssl = ssl === 'true' || ssl === '1';
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -48,6 +49,22 @@ const dbUrlToConfig = (dbUrl) => {
 | 
				
			||||||
  return config;
 | 
					  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) {
 | 
					if (cluster.isMaster) {
 | 
				
			||||||
  // Cluster master
 | 
					  // Cluster master
 | 
				
			||||||
  const core = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : Math.max(os.cpus().length - 1, 1));
 | 
					  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,
 | 
					    port:     process.env.REDIS_PORT     || 6379,
 | 
				
			||||||
    db:       process.env.REDIS_DB       || 0,
 | 
					    db:       process.env.REDIS_DB       || 0,
 | 
				
			||||||
    password: process.env.REDIS_PASSWORD,
 | 
					    password: process.env.REDIS_PASSWORD,
 | 
				
			||||||
    url:      process.env.REDIS_URL      || null,
 | 
					 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (redisNamespace) {
 | 
					  if (redisNamespace) {
 | 
				
			||||||
    redisParams.namespace = redisNamespace;
 | 
					    redisParams.namespace = redisNamespace;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const redisPrefix = redisNamespace ? `${redisNamespace}:` : '';
 | 
					  const redisPrefix = redisNamespace ? `${redisNamespace}:` : '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const redisClient = redis.createClient(redisParams);
 | 
					  const redisClient = redisUrlToClient(redisParams, process.env.REDIS_URL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const subs = {};
 | 
					  const subs = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue