小编典典

将redis部署到heroku无法连接

redis

香港专业教育学院一直试图与heroku合作。我可以成功地使其在开发模式下工作,但是当我尝试推送到heroku时,我得到了

Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):

然后,我阅读并关注了http://blog.redistogo.com/2010/07/26/resque-with-redis-to-
go/

我把站点中列出的配置放了,但是出现了以下错误

SocketError (getaddrinfo: nodename nor servname provided, or not known):

我把我的初始化器/ resque.rb

Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }

ENV["redis://redistogo:11111111111111111@lab.redistogo.com:9254/"] ||= "redis://heroku_username:heroku_password@host:9254/"
uri = URI.parse(ENV["redis://redistogo:1111111111111111@lab.redistogo.com:9254/"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

但是它引发了上面提到的错误。在我的开发模式下,我也得到了错误。

我尝试使用我的heroku用户名(即使用来自heroku的插件),将密码输入heroku,并将端口更改为9254。但是,我现在一直收到套接字错误。我究竟做错了什么?

帮助将不胜感激。谢谢

更新。

@凯文

我试过了

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

在initializer / redis.rb中也是如此,但是出现以下错误

Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):

错误中的数字(即127.0.0.1:6379)有效吗?香港专业教育学院检查我的redis gui应用程序,也从heroku配置中,我的端口号是9254

REDISTOGO_URL       => redis://redistogo:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@lab.redistogo.com:9254/

您还有其他配置设置吗?感谢您的帮助!

最后更新。

我修好了它。我简直不敢相信!我完整的解决方案是

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

逐字。它无需显式设置url就可以工作,因为我猜heroku已尝试为我设置它


阅读 365

收藏
2020-06-20

共1个答案

小编典典

对于我的设置,我有/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)

REDISTOGO_URL是在我的heroku配置中定义的。您应该能够通过键入以下内容进行验证:

heroku config --app my_app

您将在输出中看到以下值: REDISTOGO_URL

您应该REDISTOGO_URL直接从Redis To Go 复制您的内容。您可以通过在heroku中找到该实例并单击Add Ons-> Redis
To Go来找到它。

这里有一些提示:

  1. 像我上面演示的那样,从命令行验证您的heroku配置中是否具有REDIS_TO_GO URL。
  2. 验证REDIS_TO_GO URL是否与Add Ons-> Redis To Go配置中分配给该实例的URL相同。
2020-06-20