Module: Embarista::Redis

Defined in:
lib/embarista/redis.rb

Class Method Summary collapse

Class Method Details

.clientObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/embarista/redis.rb', line 6

def self.client
  $redis ||= begin
    uri = URI.parse(url)
    require 'redis'
    ::Redis.new(
      :host => uri.host,
      :port => uri.port,
      :password => uri.password
    )
  end
end

.fetch_urlObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/embarista/redis.rb', line 22

def self.fetch_url
  if App.heroku_app
    Bundler.with_clean_env do
      Timeout::timeout(30) do
        `heroku config:get REDISTOGO_URL --app #{App.heroku_app}`.chomp
      end
    end
  else
    'redis://0.0.0.0:6379/'
  end
end

.urlObject



18
19
20
# File 'lib/embarista/redis.rb', line 18

def self.url
  ENV['REDISTOGO_URL'] ||= fetch_url
end