about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakeshi Umeda <noel.yoshiba@gmail.com>2021-05-09 17:40:17 +0900
committerGitHub <noreply@github.com>2021-05-09 10:40:17 +0200
commit9b18914c3572be5b661e4d8e31578fae4ee347be (patch)
treebdca05c193a2c9833c088939175cc7970cfc9856
parentf9c2d1b9a1c1e3f6b3d79b6d2edefe4f4f5cf2a6 (diff)
Add a Redis environment variable for sidekiq (#16188)
-rw-r--r--config/initializers/sidekiq.rb11
-rw-r--r--lib/mastodon/redis_config.rb12
2 files changed, 12 insertions, 11 deletions
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index fc85a3913..219554df4 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -1,14 +1,7 @@
 # frozen_string_literal: true
 
-namespace    = ENV.fetch('REDIS_NAMESPACE') { nil }
-redis_params = { url: ENV['REDIS_URL'], driver: :hiredis }
-
-if namespace
-  redis_params[:namespace] = namespace
-end
-
 Sidekiq.configure_server do |config|
-  config.redis = redis_params
+  config.redis = REDIS_SIDEKIQ_PARAMS
 
   config.server_middleware do |chain|
     chain.add SidekiqErrorHandler
@@ -26,7 +19,7 @@ Sidekiq.configure_server do |config|
 end
 
 Sidekiq.configure_client do |config|
-  config.redis = redis_params
+  config.redis = REDIS_SIDEKIQ_PARAMS
 
   config.client_middleware do |chain|
     chain.add SidekiqUniqueJobs::Middleware::Client
diff --git a/lib/mastodon/redis_config.rb b/lib/mastodon/redis_config.rb
index d341a8484..5bfd26e34 100644
--- a/lib/mastodon/redis_config.rb
+++ b/lib/mastodon/redis_config.rb
@@ -22,9 +22,11 @@ end
 
 setup_redis_env_url
 setup_redis_env_url(:cache, false)
+setup_redis_env_url(:sidekiq, false)
 
-namespace       = ENV.fetch('REDIS_NAMESPACE', nil)
-cache_namespace = namespace ? namespace + '_cache' : 'cache'
+namespace         = ENV.fetch('REDIS_NAMESPACE', nil)
+cache_namespace   = namespace ? namespace + '_cache' : 'cache'
+sidekiq_namespace = namespace
 
 REDIS_CACHE_PARAMS = {
   driver: :hiredis,
@@ -32,3 +34,9 @@ REDIS_CACHE_PARAMS = {
   expires_in: 10.minutes,
   namespace: cache_namespace,
 }.freeze
+
+REDIS_SIDEKIQ_PARAMS = {
+  driver: :hiredis,
+  url: ENV['SIDEKIQ_REDIS_URL'],
+  namespace: sidekiq_namespace,
+}.freeze