![](/img/trans.png)
[英]URI::InvalidURIError: bad URI(is not URI?): heroku redis error
[英]Redis looking for env redis url variable not sure where to put env variable bad URI(is not URI?): (URI::InvalidURIError)
我對redis很新。 這個rails應用程序在config / initializers中有一個redis.rb文件
uri = URI.parse(ENV["REDIS_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
redis url在heroku配置上。
我不能用REDIS_URL
配置中的REDIS_URL
替換REDIS_URL
。
我收到URI解析錯誤
bad URI(is not URI?): (URI::InvalidURIError)
我的問題是我應該在哪里放置redis網址? 在哪里搜索env變量?
我猜你在做耙子的時候會得到這個。 問題是,在進行rake時,未設置環境變量,這會導致此錯誤( https://devcenter.heroku.com/articles/rails-asset-pipeline上的信息)。 要克服,請使用條件初始化程序,例如:
if ENV["REDISCLOUD_URL"]
uri = URI.parse(ENV["REDISCLOUD_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end
PS或者,使用這個,但請注意,根據Heroku:
使用此實驗室功能被認為與Heroku最佳實踐背道而馳。 此實驗室功能可以使您的構建更具確定性,並且在進行配置更改后需要重新部署。 理想情況下,您的應用應該能夠無需配置即可構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.