【问题标题】:Redis connection error on HerokuHeroku 上的 Redis 连接错误
【发布时间】:2016-09-13 14:05:27
【问题描述】:

我有一个使用 Resque 进行后台作业的 Rails 应用程序。这在本地运行良好,但在部署到 Heroku 后出现连接错误:

Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):

我看到它尝试连接到 localhost,这是不正确的。我正在使用 Heroku Redis :: Redis 加载项,并添加了 redis gem。这就是initializers.redis.rb 的样子:

$redis = Redis.new(url: ENV["REDIS_URL"])

这是我的Procfile

web: bundle exec puma -C config/puma.rb
resque: env TERM_CHILD=1 bundle exec rake resque:work QUEUE=* COUNT=1

在配置变量REDIS_URL 中添加。这里出了什么问题?

【问题讨论】:

    标签: ruby-on-rails heroku redis resque


    【解决方案1】:

    似乎在 Heroku 上使用 Puma 或 Unicorn 时,您还需要将其添加到启动过程中。我正在使用 Puma,所以我将其添加到 config/puma.rb

    on_worker_boot do
      # ...
      if defined?(Resque)
         Resque.redis = ENV["REDIS_URL"] || "redis://127.0.0.1:6379"
      end
    end
    

    以下是 Puma 和 Unicorn 的更详细说明: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server https://devcenter.heroku.com/articles/rails-unicorn#caveats

    【讨论】:

      猜你喜欢
      • 2017-10-13
      • 2021-12-02
      • 2019-07-19
      • 2012-08-02
      • 2015-08-03
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 2020-02-13
      相关资源
      最近更新 更多