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
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user