虚荣在Heroku上没有使用Redis to Go服务器

时间:2011-10-28 10:13:55

标签: heroku redis vanity

我最近在我的heroku实例中使用虚荣部署了一些A / B测试实验。但是,每当我访问仪表板,即/虚荣时,日志中会显示以下错误

- ActionView::Template::Error (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
-     1: <ul class="experiments">
-     2:   <% experiments.sort_by { |id, experiment| experiment.created_at }.reverse.each do |id, experiment| %>
-     3:     <li class="experiment <%= experiment.type %>" id="experiment_<%=vanity_h id.to_s %>">
-     4:     <%= render :file => Vanity.template("_experiment"), :locals => { :id => id, :experiment => experiment } %>
-     5:     </li>
-   

然而,redis to url似乎设置正确,虚荣似乎能够访问它 例如

irb(main):011:0> Vanity.playground.connection
=> redis://bluegill.redistogo.com:9231/0

任何人都知道我可能做错了什么?

 my vanity.rb config file is fairly standard

    development:
      adapter: redis
      connection: redis://localhost:6379/0
    qa:
      adapter: redis
      connection: <%= ENV["REDISTOGO_URL"] %>
    staging:
      adapter: redis
      connection: <%= ENV["REDISTOGO_URL"] %>
    production:
      adapter: redis
      connection: <%= ENV["REDISTOGO_URL"] %>

并且ENV [“REDISTOGO_URL”]似乎也是正确的

irb(main):012:0> ENV["REDISTOGO_URL"]
=> "redis://redistogo:e1ab3fa23beacbcd481cd4508ad0090c@bluegill.redistogo.com:9231/"

我可以从应用程序的其余部分访问Redis,似乎Vanity没有为此模板选择它..

1 个答案:

答案 0 :(得分:3)

好的,我已经想到了这一个。当我们用独角兽分叉时,我没有重新连接到正确的redis服务器而是默认为localhost。 unicorn.rb中的这段代码片段将其排除。

after_fork do |server, worker|
  # the following is *required* for Rails + "preload_app true",
  ActiveRecord::Base.establish_connection
  Vanity.playground.establish_connection(ENV["REDISTOGO_URL"]) 
end

我也确定它与其他分叉服务器类似。