From 2dda5e44f9f158f3c6d27df712fbfddf90223e05 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Fri, 14 Jun 2024 11:34:41 +0200 Subject: [PATCH] chore(kredis): use default shared connection name, fixing dossier index debounce --- app/controllers/concerns/lockable_concern.rb | 2 +- config/initializers/kredis.rb | 6 +++--- spec/controllers/concerns/lockable_concern_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/lockable_concern.rb b/app/controllers/concerns/lockable_concern.rb index f6e59743b..880085426 100644 --- a/app/controllers/concerns/lockable_concern.rb +++ b/app/controllers/concerns/lockable_concern.rb @@ -3,7 +3,7 @@ module LockableConcern included do def lock_action(key) - lock = Kredis.flag(key, config: :volatile) + lock = Kredis.flag(key) head :locked and return if lock.marked? lock.mark(expires_in: 10.seconds) diff --git a/config/initializers/kredis.rb b/config/initializers/kredis.rb index 878b8177a..48a7a7a21 100644 --- a/config/initializers/kredis.rb +++ b/config/initializers/kredis.rb @@ -1,7 +1,7 @@ -redis_volatile_options = { +redis_shared_options = { url: ENV['REDIS_CACHE_URL'], # will fallback to default redis url if empty, and won't fail if there is no redis server ssl: ENV['REDIS_CACHE_SSL'] == 'enabled' } -redis_volatile_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled' +redis_shared_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE } if ENV['REDIS_CACHE_SSL_VERIFY_NONE'] == 'enabled' -Kredis::Connections.connections[:volatile] = Redis.new(redis_volatile_options) +Kredis::Connections.connections[:shared] = Redis.new(redis_shared_options) diff --git a/spec/controllers/concerns/lockable_concern_spec.rb b/spec/controllers/concerns/lockable_concern_spec.rb index add57dc8d..dc47db17b 100644 --- a/spec/controllers/concerns/lockable_concern_spec.rb +++ b/spec/controllers/concerns/lockable_concern_spec.rb @@ -27,7 +27,7 @@ describe LockableConcern, type: :controller do context 'when there are concurrent requests' do it 'aborts the second request' do # Simulating the first request acquiring the lock - Kredis.flag(lock_key, config: :volatile).mark(expires_in: 3.seconds) + Kredis.flag(lock_key).mark(expires_in: 3.seconds) # Making the second request expect(subject).to have_http_status(:locked) @@ -36,7 +36,7 @@ describe LockableConcern, type: :controller do context 'when the lock expires' do it 'allows another request after expiration' do - Kredis.flag(lock_key, config: :volatile).mark(expires_in: 0.001.seconds) + Kredis.flag(lock_key).mark(expires_in: 0.001.seconds) sleep 0.002 expect(subject).to have_http_status(:ok)