Redis 正在寻找 env redis url 变量不确定将 env 变量放在哪里 错误 URI(不是 URI?):(URI::InvalidURIError)

编程入门 行业动态 更新时间:2024-10-18 06:02:58
本文介绍了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时,你的环境变量没有设置,这会导致这个错误(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

本文发布于:2023-10-27 11:03:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   放在   不确定   错误   redis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!