about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js19
1 files changed, 13 insertions, 6 deletions
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