Class: Gitlab::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/redis.rb

Constant Summary collapse

CACHE_NAMESPACE =
'cache:gitlab'
SESSION_NAMESPACE =
'session:gitlab'
SIDEKIQ_NAMESPACE =
'resque:gitlab'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rails_env = nil) ⇒ Redis

Returns a new instance of Redis


40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/redis.rb', line 40

def initialize(rails_env=nil)
  rails_env ||= Rails.env
  config_file = File.expand_path('../../../config/resque.yml', __FILE__)
  
  @url = "redis://localhost:6379"
  if File.exists?(config_file)
    @url =YAML.load_file(config_file)[rails_env]
  end
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url


7
8
9
# File 'lib/gitlab/redis.rb', line 7

def url
  @url
end

Class Method Details

.redis_store_optionsObject


29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/redis.rb', line 29

def self.redis_store_options
  url = new.url
  redis_config_hash = ::Redis::Store::Factory.extract_host_options_from_uri(url)
  # Redis::Store does not handle Unix sockets well, so let's do it for them
  redis_uri = URI.parse(url)
  if redis_uri.scheme == 'unix'
    redis_config_hash[:path] = redis_uri.path
  end
  redis_config_hash
end

.urlObject


16
17
18
# File 'lib/gitlab/redis.rb', line 16

def self.url
  @url || URL_MUTEX.synchronize { @url = new.url }
end

.withObject


20
21
22
23
24
25
26
27
# File 'lib/gitlab/redis.rb', line 20

def self.with
  if @pool.nil?
    POOL_MUTEX.synchronize do
      @pool = ConnectionPool.new { ::Redis.new(url: url) }
    end
  end
  @pool.with { |redis| yield redis }
end