2

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

- 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 go 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 没有为这个模板选择它。

4

1 回答 1

3

好的,我已经弄清楚了这一点。当我们使用 unicorn 分叉时,我没有重新连接到正确的 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

我确信它对于其他分叉服务器也是类似的。

于 2011-10-29T10:57:11.220 回答