ruby-on-rails – 无法连接到heroku上的redis

我在rails应用程序中使用sidekiq和active_job.该作业当前有效,但在部署到heroku时无法连接到Redis.在heroku中,我有RedisToGo插件.当推送到heroku时,我收到以下错误.

错误

/app/vendor/bundle/ruby/2.2.0/gems/redis-3.2.1/lib/redis/client.rb:331:in `rescue in establish_connection': Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)

配置/ application.rb中

config.after_initialize do
  PasswordAgingJob.perform_later
  SetOffCallJob.perform_later
end

配置/初始化/ redis.rb

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

配置/初始化/ active_job.rb

ActiveJob::Base.queue_adapter = :sidekiq
最佳答案
使用Redis URL将REDIS_PROVIDER设置为env var的名称.

输入:heroku config:设置REDIS_PROVIDER = REDISTOGO_URL.重新开始.

这里解释:https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

转载注明原文:ruby-on-rails – 无法连接到heroku上的redis - 代码日志