Class: Gitlab::Redis::Wrapper
- Inherits:
-
Object
- Object
- Gitlab::Redis::Wrapper
show all
- Defined in:
- lib/gitlab/redis/wrapper.rb
Constant Summary
collapse
- DEFAULT_REDIS_URL =
'redis://localhost:6379'
- REDIS_CONFIG_ENV_VAR_NAME =
'GITLAB_REDIS_CONFIG_FILE'
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(rails_env = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
80
81
82
|
# File 'lib/gitlab/redis/wrapper.rb', line 80
def initialize(rails_env = nil)
@rails_env = rails_env || ::Rails.env
end
|
Class Method Details
._raw_config ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/gitlab/redis/wrapper.rb', line 35
def _raw_config
return @_raw_config if defined?(@_raw_config)
@_raw_config =
begin
if filename = config_file_name
ERB.new(File.read(filename)).result.freeze
else
false
end
rescue Errno::ENOENT
false
end
end
|
.config_file_name ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/gitlab/redis/wrapper.rb', line 62
def config_file_name
file_name = ENV[REDIS_CONFIG_ENV_VAR_NAME]
return file_name unless file_name.nil?
file_name = config_file_path('resque.yml')
return file_name if File.file?(file_name)
nil
end
|
.config_file_path(filename) ⇒ Object
Return the absolute path to a Rails configuration file
We use this instead of `Rails.root` because for certain tasks utilizing these classes, `Rails` might not be available.
58
59
60
|
# File 'lib/gitlab/redis/wrapper.rb', line 58
def config_file_path(filename)
File.expand_path("../../../config/#{filename}", __dir__)
end
|
.default_url ⇒ Object
50
51
52
|
# File 'lib/gitlab/redis/wrapper.rb', line 50
def default_url
DEFAULT_REDIS_URL
end
|
.instrumentation_class ⇒ Object
75
76
77
|
# File 'lib/gitlab/redis/wrapper.rb', line 75
def instrumentation_class
raise NotImplementedError
end
|
.pool ⇒ Object
21
22
23
|
# File 'lib/gitlab/redis/wrapper.rb', line 21
def pool
@pool ||= ConnectionPool.new(size: pool_size) { ::Redis.new(params) }
end
|
.with ⇒ Object
17
18
19
|
# File 'lib/gitlab/redis/wrapper.rb', line 17
def with
pool.with { |redis| yield redis }
end
|
Instance Method Details
#params ⇒ Object
84
85
86
|
# File 'lib/gitlab/redis/wrapper.rb', line 84
def params
redis_store_options
end
|
#sentinels ⇒ Object
92
93
94
|
# File 'lib/gitlab/redis/wrapper.rb', line 92
def sentinels
raw_config_hash[:sentinels]
end
|
96
97
98
|
# File 'lib/gitlab/redis/wrapper.rb', line 96
def sentinels?
sentinels && !sentinels.empty?
end
|
#url ⇒ Object
88
89
90
|
# File 'lib/gitlab/redis/wrapper.rb', line 88
def url
raw_config_hash[:url]
end
|