Class: Gitlab::Redis::Wrapper
- Inherits:
-
Object
- Object
- Gitlab::Redis::Wrapper
show all
- Defined in:
- lib/gitlab/redis/wrapper.rb
Direct Known Subclasses
Cache, Chat, ClusterSharedState, DbLoadBalancing, FeatureFlag, Pubsub, Queues, QueuesMetadata, RateLimiting, RepositoryCache, Sessions, SharedState, SidekiqStatus, TraceChunks, Workhorse
Constant Summary
collapse
- InvalidPathError =
Class.new(StandardError)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(rails_env = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
93
94
95
|
# File 'lib/gitlab/redis/wrapper.rb', line 93
def initialize(rails_env = nil)
@rails_env = rails_env || ::Rails.env
end
|
Class Method Details
.config_fallback ⇒ Object
76
77
78
|
# File 'lib/gitlab/redis/wrapper.rb', line 76
def config_fallback
nil
end
|
.config_file_name ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/gitlab/redis/wrapper.rb', line 57
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
46
47
48
49
|
# File 'lib/gitlab/redis/wrapper.rb', line 46
def config_file_path(filename)
path = File.join(rails_root, 'config', filename)
return path if File.file?(path)
end
|
.instrumentation_class ⇒ Object
80
81
82
83
84
|
# File 'lib/gitlab/redis/wrapper.rb', line 80
def instrumentation_class
return unless defined?(::Gitlab::Instrumentation::Redis)
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end
|
.pool ⇒ Object
32
33
34
|
# File 'lib/gitlab/redis/wrapper.rb', line 32
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.
53
54
55
|
# File 'lib/gitlab/redis/wrapper.rb', line 53
def rails_root
File.expand_path('../../..', __dir__)
end
|
.redis_yml_path ⇒ Object
68
69
70
|
# File 'lib/gitlab/redis/wrapper.rb', line 68
def redis_yml_path
File.join(rails_root, 'config/redis.yml')
end
|
.store_name ⇒ Object
72
73
74
|
# File 'lib/gitlab/redis/wrapper.rb', line 72
def store_name
name.demodulize
end
|
.version ⇒ Object
28
29
30
|
# File 'lib/gitlab/redis/wrapper.rb', line 28
def version
with { |redis| redis.info['redis_version'] }
end
|
.with ⇒ Object
24
25
26
|
# File 'lib/gitlab/redis/wrapper.rb', line 24
def with
pool.with { |redis| yield redis }
end
|
Instance Method Details
#db ⇒ Object
105
106
107
|
# File 'lib/gitlab/redis/wrapper.rb', line 105
def db
redis_store_options[:db]
end
|
#params ⇒ Object
97
98
99
|
# File 'lib/gitlab/redis/wrapper.rb', line 97
def params
redis_store_options
end
|
#sentinels ⇒ Object
109
110
111
|
# File 'lib/gitlab/redis/wrapper.rb', line 109
def sentinels
raw_config_hash[:sentinels]
end
|
113
114
115
|
# File 'lib/gitlab/redis/wrapper.rb', line 113
def sentinels?
sentinels && !sentinels.empty?
end
|
#store(extras = {}) ⇒ Object
117
118
119
|
# File 'lib/gitlab/redis/wrapper.rb', line 117
def store( = {})
::Redis::Store::Factory.create(redis_store_options.merge())
end
|
#url ⇒ Object
101
102
103
|
# File 'lib/gitlab/redis/wrapper.rb', line 101
def url
raw_config_hash[:url]
end
|