将redis部署到heroku无法连接
香港专业教育学院一直试图让resoku与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.但是我现在一直收到套接字错误。 我究竟做错了什么?
帮助将不胜感激。 谢谢
UPDATE。
@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
逐字。 它没有明确设置url,因为我猜heroku试图为我设置它
对于我的设置,我有/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配置中定义的。 您应该能够通过键入以下内容来validation:
heroku config --app my_app
您将在输出中看到REDISTOGO_URL
的值
您应该直接从Redis To Go复制REDISTOGO_URL
。 您可以通过转到heroku中的实例并单击Add Ons – > Redis To Go来找到它。
这里有几个指针:
- validation您在命令行中的heroku配置中有REDIS_TO_GO URL,就像我上面演示的那样。
- validationREDIS_TO_GO URL与Add Ons – > Redis To Go配置中分配给该实例的URL相同。
我修好了它。 我简直不敢相信! 我的完整解决方案是
uri = URI.parse(ENV["REDISTOGO_URL"]) REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) Resque.redis = REDIS
逐字。 它没有明确设置url,因为我猜heroku试图为我设置它
我得到了同样的东西,所以,基本上Sidekiq没有从vars抓住REDISCLOUD_URL,它抓住了REDIS_PROVIDER。
heroku config:set REDIS_PROVIDER=REDISCLOUD_URL
它就像一个魅力。
- rails assets:在slug期间为s3错误预编译:当设置env时,雾提供程序和目录不能为空
- 如何通过Heroku Scheduler停止正在运行Rails任务的Heroku Dyno?
- Rails asset_host,cloudfront和heroku
- IMAP闲置如何工作?
- 部署到Heroku时,Rails custom.css无法正常工作
- 预编译资产失败ExecJS :: ProgramError:意外的标记:operator(=)(行:10770,col:0,pos:300859)
- Heroku:保存缓存时遇到错误
- 使用Heroku的分支策略进行良好的Git部署?
- 如何在Heroku上安排“每周”工作?