我对 redis 很陌生.这个 rails 应用程序在 config/initializers 中有一个 redis.rb 文件
I am quite new to redis. This rails application has a redis.rb file in config/initializers
uri = URI.parse(ENV["REDIS_URL"]) $redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)redis url 位于 heroku 配置中.
The redis url is on heroku config.
我不能只用 heroku 配置中的 REDIS_URL 替换 REDIS_URL.
I can't just replace REDIS_URL with the REDIS_URL from heroku config.
我收到 URI 解析错误
I am getting a URI parse error
bad URI(is not URI?): (URI::InvalidURIError)我的问题是我应该把redis url放在哪里?它从哪里搜索 env 变量?
my question is where should I place the redis url ? where is it searching the env variable from?
推荐答案我猜你在做 rake 时会遇到这个问题.问题是,当耙ing时,你的环境变量没有设置,这会导致这个错误(devcenter.heroku/articles/rails-asset-pipeline).要克服,请改用条件初始化器,例如:
I'm guessing you're getting this when doing rake. The problem is that when rake-ing, your environment variables aren't set, which leads to this error (info at devcenter.heroku/articles/rails-asset-pipeline). To overcome, use a conditional intializer instead, e.g.:
if ENV["REDISCLOUD_URL"] uri = URI.parse(ENV["REDISCLOUD_URL"]) $redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) end附言或者,使用 this 但请注意,根据 Heroku:
P.S. alternatively, use this but note that according to Heroku:
使用此实验室功能被认为与 Heroku 最佳实践背道而驰.此实验室功能可以使您的构建不那么确定性并且需要更改配置后重新部署.理想情况下,您的应用程序应该能够无需配置即可构建.
Using this labs feature is considered counter to Heroku best practices. This labs feature can make your builds less deterministic and require re-deploys after making config changes. Ideally your app should be able to build without config.
更多推荐
Redis 正在寻找 env redis url 变量不确定将 env 变量放在哪里 错误 URI(不是 URI?):(URI::InvalidURIError
发布评论