Redis 正在寻找 env redis url 变量 不确定将 env 变量放在哪里 错误 URI(不是 URI?):(URI::InvalidURIError) [英] Redis looking for env redis url variable not sure where to put env variable bad URI(is not URI?): (URI::InvalidURIError)

查看:27
本文介绍了Redis 正在寻找 env redis url 变量 不确定将 env 变量放在哪里 错误 URI(不是 URI?):(URI::InvalidURIError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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时,你的环境变量没有设置,这会导致这个错误(https://devcenter.heroku.com/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 https://devcenter.heroku.com/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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆