Class: Gitlab::Redis::Wrapper
- Inherits:
-
Object
- Object
- Gitlab::Redis::Wrapper
show all
- Defined in:
- lib/gitlab/redis/wrapper.rb
Direct Known Subclasses
ActionCable, Cache, Chat, DbLoadBalancing, FeatureFlag, MultiStoreWrapper, Queues, QueuesMetadata, RateLimiting, RepositoryCache, Sessions, SharedState, TraceChunks, Workhorse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(rails_env = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
114
115
116
|
# File 'lib/gitlab/redis/wrapper.rb', line 114
def initialize(rails_env = nil)
@rails_env = rails_env || ::Rails.env
end
|
Class Method Details
99
100
101
|
# File 'lib/gitlab/redis/wrapper.rb', line 99
def active?
true
end
|
.config_fallback ⇒ Object
85
86
87
|
# File 'lib/gitlab/redis/wrapper.rb', line 85
def config_fallback
nil
end
|
.config_file_name ⇒ Object
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/gitlab/redis/wrapper.rb', line 66
def config_file_name
[
config_file_path("redis.#{store_name.underscore}.yml"),
config_fallback&.config_file_name
].compact.first
end
|
.config_file_path(filename) ⇒ Object
54
55
56
57
58
|
# File 'lib/gitlab/redis/wrapper.rb', line 54
def config_file_path(filename)
path = File.join(rails_root, 'config', filename)
path if File.file?(path)
end
|
.instrumentation_class ⇒ Object
89
90
91
92
93
|
# File 'lib/gitlab/redis/wrapper.rb', line 89
def instrumentation_class
return unless defined?(::Gitlab::Instrumentation::Redis)
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end
|
.params ⇒ Object
22
23
24
|
# File 'lib/gitlab/redis/wrapper.rb', line 22
def params
@params ||= new.params.freeze
end
|
.pool ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/gitlab/redis/wrapper.rb', line 35
def pool
@pool ||= if config_fallback &&
config_fallback.params.except(:instrumentation_class) == params.except(:instrumentation_class)
config_fallback.pool
else
ConnectionPool.new(size: pool_size, name: store_name.underscore) { redis }
end
end
|
.rails_root ⇒ Object
We need this local implementation of Rails.root because MailRoom doesn’t load Rails.
62
63
64
|
# File 'lib/gitlab/redis/wrapper.rb', line 62
def rails_root
File.expand_path('../../..', __dir__)
end
|
.redis ⇒ Object
95
96
97
|
# File 'lib/gitlab/redis/wrapper.rb', line 95
def redis
init_redis(params)
end
|
.redis_yml_path ⇒ Object
77
78
79
|
# File 'lib/gitlab/redis/wrapper.rb', line 77
def redis_yml_path
File.join(rails_root, 'config/redis.yml')
end
|
.store_name ⇒ Object
81
82
83
|
# File 'lib/gitlab/redis/wrapper.rb', line 81
def store_name
name.demodulize
end
|
.version ⇒ Object
31
32
33
|
# File 'lib/gitlab/redis/wrapper.rb', line 31
def version
with { |redis| redis.info['redis_version'] }
end
|
.with ⇒ Object
Also known as:
then
26
27
28
|
# File 'lib/gitlab/redis/wrapper.rb', line 26
def with
pool.with { |redis| yield redis }
end
|
Instance Method Details
#db ⇒ Object
148
149
150
|
# File 'lib/gitlab/redis/wrapper.rb', line 148
def db
redis_store_options[:db] || 0
end
|
#encrypted_secrets ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/gitlab/redis/wrapper.rb', line 178
def encrypted_secrets
Settings.encrypted(secret_file) if (secret_file && File.exist?(secret_file)) ||
(defined?(Gitlab::Runtime) && Gitlab::Runtime.rake?)
end
|
#params ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/gitlab/redis/wrapper.rb', line 118
def params
options = redis_store_options
options[:command_builder] = CommandBuilder
options[:custom] = { instrumentation_class: self.class.store_name }
if options[:sentinels]
options[:name] = options[:host]
options.except(:scheme, :instrumentation_class, :host, :port)
elsif options[:cluster]
options[:nodes] = options[:cluster].map { |c| c.except(:scheme) }
options.except(:scheme, :instrumentation_class, :cluster)
else
options.except(:scheme, :instrumentation_class)
end
end
|
#secret_file ⇒ Object
160
161
162
163
164
165
166
167
168
|
# File 'lib/gitlab/redis/wrapper.rb', line 160
def secret_file
return unless defined?(Settings)
if raw_config_hash[:secret_file].blank?
File.join(Settings.encrypted_settings['path'], 'redis.yaml.enc')
else
Settings.absolute(raw_config_hash[:secret_file])
end
end
|
#sentinels ⇒ Object
156
157
158
|
# File 'lib/gitlab/redis/wrapper.rb', line 156
def sentinels
raw_config_hash[:sentinels]
end
|
170
171
172
|
# File 'lib/gitlab/redis/wrapper.rb', line 170
def sentinels?
sentinels && !sentinels.empty?
end
|
#ssl_params ⇒ Object
152
153
154
|
# File 'lib/gitlab/redis/wrapper.rb', line 152
def ssl_params
raw_config_hash[:ssl_params]
end
|
#store(extras = {}) ⇒ Object
174
175
176
|
# File 'lib/gitlab/redis/wrapper.rb', line 174
def store( = {})
::Redis::Store::Factory.create(params.merge())
end
|
#url ⇒ Object
144
145
146
|
# File 'lib/gitlab/redis/wrapper.rb', line 144
def url
raw_config_hash[:url]
end
|