19

我一直试图让 resque 与 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)

在初始化程序/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 已经尝试为我设置它

4

3 回答 3

40

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

MyREDISTOGO_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 相同。
于 2012-05-19T02:19:27.557 回答
15

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

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

逐字。它可以在没有明确设置 url 的情况下工作,因为我猜 heroku 已经尝试为我设置它

于 2012-05-19T09:08:57.863 回答
11

我得到了同样的东西,所以,基本上 Sidekiq 并没有从 vars 中获取 REDISCLOUD_URL,它是在获取 REDIS_PROVIDER。

heroku config:set REDIS_PROVIDER=REDISCLOUD_URL

它就像一个魅力。

于 2015-06-09T04:15:44.170 回答