Class: Gitlab::Redis::Wrapper
- Inherits:
-
Object
- Object
- Gitlab::Redis::Wrapper
show all
- Defined in:
- lib/gitlab/redis/wrapper.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(rails_env = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
115
116
117
|
# File 'lib/gitlab/redis/wrapper.rb', line 115
def initialize(rails_env = nil)
@rails_env = rails_env || ::Rails.env
end
|
Class Method Details
._raw_config ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/gitlab/redis/wrapper.rb', line 44
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_fallback ⇒ Object
98
99
100
|
# File 'lib/gitlab/redis/wrapper.rb', line 98
def config_fallback
nil
end
|
.config_fallback? ⇒ Boolean
70
71
72
|
# File 'lib/gitlab/redis/wrapper.rb', line 70
def config_fallback?
config_file_name == config_fallback&.config_file_name
end
|
.config_file_name ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/gitlab/redis/wrapper.rb', line 74
def config_file_name
[
ENV["GITLAB_REDIS_#{store_name.underscore.upcase}_CONFIG_FILE"],
config_file_path("redis.#{store_name.underscore}.yml"),
config_fallback&.config_file_name,
ENV['GITLAB_REDIS_CONFIG_FILE'],
config_file_path('resque.yml')
].compact.first
end
|
.config_file_path(filename) ⇒ Object
59
60
61
62
|
# File 'lib/gitlab/redis/wrapper.rb', line 59
def config_file_path(filename)
path = File.join(rails_root, 'config', filename)
return path if File.file?(path)
end
|
.instrumentation_class ⇒ Object
102
103
104
105
106
|
# File 'lib/gitlab/redis/wrapper.rb', line 102
def instrumentation_class
return unless defined?(::Gitlab::Instrumentation::Redis)
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end
|
.pool ⇒ Object
30
31
32
|
# File 'lib/gitlab/redis/wrapper.rb', line 30
def pool
@pool ||= ConnectionPool.new(size: pool_size) { redis }
end
|
.rails_root ⇒ Object
We need this local implementation of Rails.root because MailRoom doesn't load Rails.
66
67
68
|
# File 'lib/gitlab/redis/wrapper.rb', line 66
def rails_root
File.expand_path('../../..', __dir__)
end
|
.store_name ⇒ Object
94
95
96
|
# File 'lib/gitlab/redis/wrapper.rb', line 94
def store_name
name.demodulize
end
|
.version ⇒ Object
26
27
28
|
# File 'lib/gitlab/redis/wrapper.rb', line 26
def version
with { |redis| redis.info['redis_version'] }
end
|
.with ⇒ Object
22
23
24
|
# File 'lib/gitlab/redis/wrapper.rb', line 22
def with
pool.with { |redis| yield redis }
end
|
Instance Method Details
#db ⇒ Object
127
128
129
|
# File 'lib/gitlab/redis/wrapper.rb', line 127
def db
redis_store_options[:db]
end
|
#params ⇒ Object
119
120
121
|
# File 'lib/gitlab/redis/wrapper.rb', line 119
def params
redis_store_options
end
|
#sentinels ⇒ Object
131
132
133
|
# File 'lib/gitlab/redis/wrapper.rb', line 131
def sentinels
raw_config_hash[:sentinels]
end
|
135
136
137
|
# File 'lib/gitlab/redis/wrapper.rb', line 135
def sentinels?
sentinels && !sentinels.empty?
end
|
#store(extras = {}) ⇒ Object
139
140
141
|
# File 'lib/gitlab/redis/wrapper.rb', line 139
def store( = {})
::Redis::Store::Factory.create(redis_store_options.merge())
end
|
#url ⇒ Object
123
124
125
|
# File 'lib/gitlab/redis/wrapper.rb', line 123
def url
raw_config_hash[:url]
end
|