如何为 Dashing 启用 redis?

How to enable redis for Dashing?

我使用免费的 heroku 实例 运行 我的 Dashing 项目。结果,当我的实例休眠时,它丢失了之前传递的值。我被推荐使用 Redis 来保存历史。我尝试按照 here 给出的说明进行操作。结果我得到了以下 config.ru(作为我的潇洒项目的一部分):

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

以及以下 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'

但这并没有帮助。我做错了什么? 我也尝试使用 this 教程。但它在 redis_uri = URI.parse(ENV["REDISTOGO_URL"]) 行给我一个错误(类似于 wrong url is given)。

问题是该应用需要加载项 Redis To Go
如果配置了Redis To Go,在环境变量中加入REDISTOGO_URL,就可以了

有关如何设置 Redis To Go 的更多信息,请阅读 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.