LA_ LA_ - 7 months ago 33
Ruby Question

How to enable redis for Dashing?

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
).

Answer

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.

Comments