0

I use free heroku instance to run my Dashing project. In result, it looses the value passed previously, when my instance sleeps. I was recommended to use Redis to keep history. I tryed to follow the instruction given here. In result I got the following config.ru (as part of my dashing project):

require 'dashing'
require 'redis-objects'
require 'yaml'

configure do
  set :auth_token, 'my-token'
  set :default_dashboard, 'def' # https://github.com/Shopify/dashing/wiki/How-To:-Change-the-default-dashboard

  helpers do
    def protected!
     # Put any authentication code you want in here.
     # This method is run before accessing any resource.
    end
  end
end

def redis?
  ENV.has_key? 'REDISTOGO_URL'
end

if redis?
  redis_uri = URI.parse(ENV['REDISTOGO_URL'])
  Redis.current = Redis.new(:host => redis_uri.host,
      :port => redis_uri.port,
      :password => redis_uri.password)

  set :history, Redis::HashKey.new('dashing-history')
elsif File.exists?(settings.history_file)
  set history: YAML.load_file(settings.history_file)
else
  set history: {}
end

map Sinatra::Application.assets_prefix do
  run Sinatra::Application.sprockets
end

run Sinatra::Application

and the following Gemfile:

source 'https://rubygems.org'

gem 'dashing'
gem 'redis-objects'

## Remove this if you don't need a twitter widget.
gem 'twitter', '>= 5.9.0'

But it didn't help. What I did incorrectly? I also tried to use this tutorial. But it was giving me an error at line redis_uri = URI.parse(ENV["REDISTOGO_URL"]) (something like wrong url is given).

LA_
  • 19,823
  • 58
  • 172
  • 308
  • Do you have REDISTOGO_URL stored in your environment variables? – sudo bangbang Mar 02 '16 at 04:52
  • @sudobangbang, I think no. How should I add it there? – LA_ Mar 02 '16 at 05:30
  • You can go to your heroku dash board, go to settings tab ```https://dashboard.heroku.com/apps/project_name/settings``` You can see Config variables. Just add key value pairs – sudo bangbang Mar 02 '16 at 05:37
  • @sudobangbang, thanks! should I have redis installed somewhere? Could it be Heroku? I.e. what should be the key value? – LA_ Mar 02 '16 at 08:57
  • as redis-objects is in your Gemfile, bundle will take care of it. > Could it be Heroku? - I don't understand this question. key: REDISTOGO_URL, value: value fo REDISTOGO_URL – sudo bangbang Mar 02 '16 at 09:36
  • @sudobangbang, ok, got it now - I was supposed to install redistogo manually, here is the manual - https://devcenter.heroku.com/articles/redistogo (`REDISTOGO_URL` is added automatically to env variables in this case). Will check if it works now. – LA_ Mar 02 '16 at 18:33
  • @sudobangbang, could you please post your comment as the answer - so I will be able to accept it. – LA_ Mar 03 '16 at 19:16

1 Answers1

2

The problem was that the app requires the add-on Redis To Go
If Redis To Go is configured, REDISTOGO_URL is added to environment variables, it will work

For more information on how to setup Redis To Go, read the heroku article

Adding Redis to an application provides benefits, you may be using RedisToGo to power simple Resque or Sidekiq jobs, or using the raw power of Redis 2.6 Lua Scripting to do some crazy fast operations. Redis can be used a database, but it’s often used as a complementary datastore. With over 140 commands, the possibilities are endless.

Community
  • 1
  • 1
sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
  • @LA_: Please edit the answer with your findings when you set up **Redis To Go** so that anyone having the same problem in the future can benefit from it – sudo bangbang Mar 04 '16 at 05:41