about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-05-07 13:42:32 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-07 19:42:32 +0200
commit5c1f70b5c577123cc42e073dea6a8f72e27818f8 (patch)
tree1d7fe709a98f6d97ded8db4a020f80efe44b9e01 /streaming
parentc7848f54ffd67189e368e9d981565076dbb5e770 (diff)
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
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