2016-05-15 115 views
0

我跟隨Ryan Bates教程ActionController Live,並在heroku上部署應用程序。所有的工作都很好,除了事件,瑞安傷心,我們應該重新打開Redis連接,我不能這樣做。我使用RedisToGo在heroku上執行redis。 這裏我的事件控制器操作:Heroku Redis無法打開連接

def events 
    response.headers["Content-Type"] = "text/event-stream" 
    redis = Redis.new(:url => uri) 
    redis.psubscribe('messages.*') do |on| 
     on.pmessage do |pattern, event, data| 
      response.stream.write("event: #{event}\n") 
      response.stream.write("data: #{data}\n\n") 
     end 
    end 
    rescue IOError 
     logger.info "Stream closed" 
    ensure 
     redis.quit 
     response.stream.close 
end 

而且,這裏的Redis初始化:

uri = URI.parse(ENV["REDISTOGO_URL"]) 
REDIS = Redis.new(:url => uri) 

有人能幫助我嗎?

編輯

我都只是初始化使用Redis.new(url: ENV["REDISTOGO_URL"])客戶端,而不是解析的URI的事件控制器行動工作。

回答

0

替換此:

redis = Redis.new(:url => uri) 
redis.psubscribe 

與此:

REDIS.psubscribe 

任何地方,你有 'Redis的' 上面,與Redis的全局替換。

+0

這不解決問題,事件does not發生,沒有發生錯誤 – jealrockone

+0

你有REDIS = Redis.new在你的config/initializers某處,對嗎? – court3nay

+0

不,只有這個REDIS = Redis.new(:url => uri) – jealrockone