无法连接到heroku上的redis

Ant*_*yrd 10 ruby ruby-on-rails heroku redis sidekiq

我在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)
Run Code Online (Sandbox Code Playgroud)

配置/ application.rb中

config.after_initialize do
  PasswordAgingJob.perform_later
  SetOffCallJob.perform_later
end
Run Code Online (Sandbox Code Playgroud)

配置/初始化/ redis.rb

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

配置/初始化/ active_job.rb

ActiveJob::Base.queue_adapter = :sidekiq
Run Code Online (Sandbox Code Playgroud)

Mik*_*ham 18

REDIS_PROVIDER使用Redis URL 设置为env var的名称.

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

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