无法连接到heroku上的redis

时间:2021-09-23 03:01:07

I'm using sidekiq with active_job in my rails application. The job currently works but I am unable to get connect to the Redis when deploying to heroku. In heroku I have the RedisToGo addon. When pushing to heroku I get the following error.

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

error

/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)

config/application.rb

config.after_initialize do
  PasswordAgingJob.perform_later
  SetOffCallJob.perform_later
end

config/initializers/redis.rb

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

config/initializers/active_job.rb

ActiveJob::Base.queue_adapter = :sidekiq

3 个解决方案

#1


11  

Set REDIS_PROVIDER to the name of the env var with your Redis URL.

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

Type this: heroku config:set REDIS_PROVIDER=REDISTOGO_URL. Restart.

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

Explained here: https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

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

#2


2  

You must set the REDISTOGO_URL on Heroku.

您必须在Heroku上设置REDISTOGO_URL。

Click on Settings, and then Reveal Config Vars.

单击“设置”,然后单击“显示配置变量”。

#3


2  

Setting REDIS_URL in heroku config help me to resolve:

在heroku配置中设置REDIS_URL有助于我解决:

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

#1


11  

Set REDIS_PROVIDER to the name of the env var with your Redis URL.

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

Type this: heroku config:set REDIS_PROVIDER=REDISTOGO_URL. Restart.

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

Explained here: https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an-env-variable

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

#2


2  

You must set the REDISTOGO_URL on Heroku.

您必须在Heroku上设置REDISTOGO_URL。

Click on Settings, and then Reveal Config Vars.

单击“设置”,然后单击“显示配置变量”。

#3


2  

Setting REDIS_URL in heroku config help me to resolve:

在heroku配置中设置REDIS_URL有助于我解决:

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