From a1ecdb0e67db0e582e92299f44c1dc2a8126d30b Mon Sep 17 00:00:00 2001 From: Max Fierke Date: Sun, 5 Nov 2023 11:24:25 -0600 Subject: [PATCH] Enable redis-based caching in production Setting some pretty low-timeouts by default --- config/environments/production.rb | 11 +++++++++++ config/initializers/sidekiq.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 03bb6afe..2b512e3a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -51,6 +51,17 @@ # Use a different cache store in production. # config.cache_store = :mem_cache_store + redis_url = ENV["CACHE_REDIS_URL"].presence || ENV["REDIS_URL"] + if redis_url.present? + config.cache_store = :redis_cache_store, { + url: redis_url, + connect_timeout: 1, + read_timeout: 0.2, + write_timeout: 0.2, + reconnect_attempts: 1, + } + end + # Use a real queuing backend for Active Job (and separate queues per environment). # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "resumis_production" diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 5e33df38..f50d375b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,4 +1,4 @@ -redis_url = ENV['REDIS_URL'].presence || 'redis://localhost:6379/1' +redis_url = ENV["SIDEKIQ_REDIS_URL"].presence || ENV["REDIS_URL"].presence || 'redis://localhost:6379/1' Sidekiq.configure_server do |config| config.redis = { url: redis_url } end