将redis部署到heroku无法连接

时间:2012-05-18 23:38:27

标签: ruby-on-rails heroku redis resque

我一直试图让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中的add),将我的密码输入heroku,并将端口更改为9254.但是我现在一直收到套接字错误。我做错了什么?

帮助将不胜感激。谢谢

更新。

@kevin

我试过

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

逐字。它没有明确设置网址,因为我猜heroku试图为我设置它

3 个答案:

答案 0 :(得分: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)

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

heroku config --app my_app

您会在输出中看到REDISTOGO_URL

的值

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

以下是一些指示:

  1. 从上面演示的命令行验证您的heroku配置中是否有REDIS_TO_GO URL。
  2. 验证REDIS_TO_GO网址与Add Ons中分配给该实例的网址相同 - > Redis To Go配置。

答案 1 :(得分:15)

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

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

逐字。它没有明确设置网址,因为我猜heroku试图为我设置它

答案 2 :(得分:11)

我得到了同样的东西,所以,基本上Sidekiq没有从vars抓住REDISCLOUD_URL,它抓住了REDIS_PROVIDER。

heroku config:set REDIS_PROVIDER=REDISCLOUD_URL

它就像一个魅力。

相关问题