Class: Relax::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/relax/base.rb

Direct Known Subclasses

Bot, EventListener

Class Method Summary collapse

Class Method Details

.redisObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/relax/base.rb', line 3

def self.redis
  if uri = ENV['REDISCLOUD_URL']
    redis_uri = URI.parse(uri)
  elsif uri = ENV['REDISTOGO_URL']
    redis_uri = URI.parse(uri)
  elsif uri = ENV['REDIS_URL']
    redis_uri = URI.parse(uri)
  else
    redis_uri = URI.parse("redis://localhost:6379")
  end

  if !defined?(@@conn)
    @@conn = ConnectionPool.new(timeout: 1, size: 2) do
      Redis.new(url: redis_uri, db: 0)
    end
  end

  @@conn
end