From 9122823afca108ffc7019261c7e8f255d640066b Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 8 Aug 2014 17:56:01 +0200 Subject: Configure Redis cache for all environments Also add support for connecting to Redis with Unix sockets. --- config/environments/production.rb | 10 ---------- config/initializers/7_cache_settings.rb | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 config/initializers/7_cache_settings.rb (limited to 'config') diff --git a/config/environments/production.rb b/config/environments/production.rb index 2450d5719eb..78bf543402b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -45,16 +45,6 @@ Gitlab::Application.configure do # Use a different logger for distributed setups # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - # Use a different cache store in production - config_file = Rails.root.join('config', 'resque.yml') - - resque_url = if File.exists?(config_file) - YAML.load_file(config_file)[Rails.env] - else - "redis://localhost:6379" - end - config.cache_store = :redis_store, resque_url, {namespace: 'cache:gitlab'} - # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/config/initializers/7_cache_settings.rb b/config/initializers/7_cache_settings.rb new file mode 100644 index 00000000000..7dbaf2e1c9e --- /dev/null +++ b/config/initializers/7_cache_settings.rb @@ -0,0 +1,18 @@ +redis_config_file = Rails.root.join('config', 'resque.yml') + +resque_url = if File.exists?(redis_config_file) + YAML.load_file(redis_config_file)[Rails.env] + else + "redis://localhost:6379" + end + +# Redis::Store does not handle Unix sockets well, so let's do it for them +redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(resque_url) +redis_uri = URI.parse(resque_url) +if redis_uri.scheme == 'unix' + redis_config_hash[:path] = redis_uri.path +end + +redis_config_hash[:namespace] = 'cache:gitlab' + +Gitlab::Application.config.cache_store = :redis_store, redis_config_hash -- cgit v1.2.1 From c0b146899b46892485727102f552a1db324bb2ef Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 8 Aug 2014 17:56:33 +0200 Subject: Store sessions in a Redis namespace This makes less of a mess of the Redis root. --- config/initializers/session_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 5fe5270236b..bff4b8d097a 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -2,7 +2,7 @@ Gitlab::Application.config.session_store( :redis_store, # Using the cookie_store would enable session replay attacks. - servers: Gitlab::Application.config.cache_store[1], # re-use the Redis config from the Rails cache store + servers: Gitlab::Application.config.cache_store[1].merge(namespace: 'session:gitlab'), # re-use the Redis config from the Rails cache store key: '_gitlab_session', secure: Gitlab.config.gitlab.https, httponly: true, -- cgit v1.2.1 From 6d785abaa9367173d62300b8000a68554e4e293c Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Mon, 11 Aug 2014 18:26:20 +0200 Subject: Rename resque_url to redis_url_string --- config/initializers/7_cache_settings.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'config') diff --git a/config/initializers/7_cache_settings.rb b/config/initializers/7_cache_settings.rb index 7dbaf2e1c9e..ce7e8c5a650 100644 --- a/config/initializers/7_cache_settings.rb +++ b/config/initializers/7_cache_settings.rb @@ -1,14 +1,14 @@ redis_config_file = Rails.root.join('config', 'resque.yml') -resque_url = if File.exists?(redis_config_file) - YAML.load_file(redis_config_file)[Rails.env] - else - "redis://localhost:6379" - end +redis_url_string = if File.exists?(redis_config_file) + YAML.load_file(redis_config_file)[Rails.env] + else + "redis://localhost:6379" + end # Redis::Store does not handle Unix sockets well, so let's do it for them -redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(resque_url) -redis_uri = URI.parse(resque_url) +redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(redis_url_string) +redis_uri = URI.parse(redis_url_string) if redis_uri.scheme == 'unix' redis_config_hash[:path] = redis_uri.path end -- cgit v1.2.1 From 0a52b70b923af6d4351d4b7a28527c6740e812cf Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 27 Aug 2014 16:36:38 +0200 Subject: Hide configuration shenanigans in a block I'm feeling paranoid about the scope variables like redis_config_file get defined in. Hiding it in a block to limit the scope. --- config/initializers/7_cache_settings.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'config') diff --git a/config/initializers/7_cache_settings.rb b/config/initializers/7_cache_settings.rb index ce7e8c5a650..5367a4d431c 100644 --- a/config/initializers/7_cache_settings.rb +++ b/config/initializers/7_cache_settings.rb @@ -1,18 +1,20 @@ -redis_config_file = Rails.root.join('config', 'resque.yml') +Gitlab::Application.configure do + redis_config_file = Rails.root.join('config', 'resque.yml') -redis_url_string = if File.exists?(redis_config_file) - YAML.load_file(redis_config_file)[Rails.env] - else - "redis://localhost:6379" - end + redis_url_string = if File.exists?(redis_config_file) + YAML.load_file(redis_config_file)[Rails.env] + else + "redis://localhost:6379" + end -# Redis::Store does not handle Unix sockets well, so let's do it for them -redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(redis_url_string) -redis_uri = URI.parse(redis_url_string) -if redis_uri.scheme == 'unix' - redis_config_hash[:path] = redis_uri.path -end + # Redis::Store does not handle Unix sockets well, so let's do it for them + redis_config_hash = Redis::Store::Factory.extract_host_options_from_uri(redis_url_string) + redis_uri = URI.parse(redis_url_string) + if redis_uri.scheme == 'unix' + redis_config_hash[:path] = redis_uri.path + end -redis_config_hash[:namespace] = 'cache:gitlab' + redis_config_hash[:namespace] = 'cache:gitlab' -Gitlab::Application.config.cache_store = :redis_store, redis_config_hash + config.cache_store = :redis_store, redis_config_hash +end -- cgit v1.2.1