From 5c1f70b5c577123cc42e073dea6a8f72e27818f8 Mon Sep 17 00:00:00 2001 From: beatrix Date: Sun, 7 May 2017 13:42:32 -0400 Subject: namespace redis usage (#2869) * add redis-namespace gem * namespace redis usage * refactor redis namespace code to be less intrusive previously : would be prepended to keys when the REDIS_NAMESPACE env var was not set now if it is not set the namespacing functions are not used at all, which should prevent disruptions when instances update. * fix redis namespace variable style in streaming js * remove trailing space * final redis namespace style fix --- streaming/index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'streaming') diff --git a/streaming/index.js b/streaming/index.js index 3a7764ee9..d3fb8d647 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -87,13 +87,21 @@ if (cluster.isMaster) { const pgPool = new pg.Pool(Object.assign(pgConfigs[env], dbUrlToConfig(process.env.DATABASE_URL))) const server = http.createServer(app) const wss = new WebSocket.Server({ server }) + const redisNamespace = process.env.REDIS_NAMESPACE || null - const redisClient = redis.createClient({ + const redisParams = { host: process.env.REDIS_HOST || '127.0.0.1', port: process.env.REDIS_PORT || 6379, 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 subs = {} @@ -105,11 +113,10 @@ if (cluster.isMaster) { if (!callbacks) { return } - callbacks.forEach(callback => callback(message)) }) - redisClient.psubscribe('timeline:*') + redisClient.psubscribe(`${redisPrefix}timeline:*`) const subscribe = (channel, callback) => { log.silly(`Adding listener for ${channel}`) @@ -242,8 +249,8 @@ if (cluster.isMaster) { } } - subscribe(id, listener) - attachCloseHandler(id, listener) + subscribe(`${redisPrefix}${id}`, listener) + attachCloseHandler(`${redisPrefix}${id}`, listener) } // Setup stream output to HTTP -- cgit