[英]Redis connection error on Heroku
我有一個使用Resque進行后台作業的Rails應用程序。 這在本地可以正常工作,但是在部署到Heroku之后,我得到一個連接錯誤:
Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
我看到它嘗試連接到本地主機,這是不正確的。 我正在使用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
。 這是怎么了?
似乎在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.