4

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)

The redis url is on heroku config.

I can't just replace REDIS_URL with the REDIS_URL from heroku config.

I am getting a URI parse error

 bad URI(is not URI?):  (URI::InvalidURIError)

my question is where should I place the redis url ? where is it searching the env variable from?

Jngai1297
  • 2,415
  • 5
  • 29
  • 63
  • Looks like you haven't configured your `ENV['REDIS_URL']` variable correctly, because it's passing `nil` to `URI.parse()`: – Mike Campbell Apr 23 '14 at 15:00
  • @MikeCampbell I assumed that it got set up correctly. I inherited the app from someone. Its nice to know that I need to double check. – Jngai1297 Apr 23 '14 at 15:06

1 Answers1

5

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

P.S. alternatively, use this but note that according to 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.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117