【发布时间】:2012-05-26 12:34:00
【问题描述】:
我一直在努力争取与 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 已经尝试为我设置它
【问题讨论】:
-
最后的更新使它对我有用。它应该去
config/initializers/redis.rb -
太棒了!你节省了我的时间。您应该将解决方案作为单独的答案发布。
标签: ruby-on-rails heroku redis resque