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.
84
85
86
|
# File 'lib/gitlab/redis/wrapper.rb', line 84
def initialize(rails_env = nil)
@rails_env = rails_env || ::Rails.env
end
|
Class Method Details
._raw_config ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/gitlab/redis/wrapper.rb', line 39
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
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/gitlab/redis/wrapper.rb', line 66
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.
62
63
64
|
# File 'lib/gitlab/redis/wrapper.rb', line 62
def config_file_path(filename)
File.expand_path("../../../config/#{filename}", __dir__)
end
|
.default_url ⇒ Object
54
55
56
|
# File 'lib/gitlab/redis/wrapper.rb', line 54
def default_url
DEFAULT_REDIS_URL
end
|
.instrumentation_class ⇒ Object
79
80
81
|
# File 'lib/gitlab/redis/wrapper.rb', line 79
def instrumentation_class
raise NotImplementedError
end
|
.pool ⇒ Object
25
26
27
|
# File 'lib/gitlab/redis/wrapper.rb', line 25
def pool
@pool ||= ConnectionPool.new(size: pool_size) { ::Redis.new(params) }
end
|
.version ⇒ Object
21
22
23
|
# File 'lib/gitlab/redis/wrapper.rb', line 21
def version
with { |redis| redis.info['redis_version'] }
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
88
89
90
|
# File 'lib/gitlab/redis/wrapper.rb', line 88
def params
redis_store_options
end
|
#sentinels ⇒ Object
96
97
98
|
# File 'lib/gitlab/redis/wrapper.rb', line 96
def sentinels
raw_config_hash[:sentinels]
end
|
100
101
102
|
# File 'lib/gitlab/redis/wrapper.rb', line 100
def sentinels?
sentinels && !sentinels.empty?
end
|
#url ⇒ Object
92
93
94
|
# File 'lib/gitlab/redis/wrapper.rb', line 92
def url
raw_config_hash[:url]
end
|