diff --git a/Gemfile b/Gemfile index f11513c..47db8b9 100644 --- a/Gemfile +++ b/Gemfile @@ -61,4 +61,4 @@ gem 'will_paginate', '~> 4.0' gem 'rack-cors', '~> 2.0', '>= 2.0.2' gem 'rack-attack', '~> 6.7' -gem 'redis', '>= 4.0.1' +gem 'redis', '~> 5.0' diff --git a/Gemfile.lock b/Gemfile.lock index cd5ca29..aafd081 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -229,8 +229,8 @@ GEM prism (>= 1.6.0) rbs (>= 4.0.0) tsort - redis (6.0.0) - redis-client (= 0.30.1) + redis (5.4.1) + redis-client (>= 0.22.0) redis-client (0.30.1) connection_pool regexp_parser (2.12.0) @@ -290,7 +290,7 @@ DEPENDENCIES rack-attack (~> 6.7) rack-cors (~> 2.0, >= 2.0.2) rails (~> 7.2.3, >= 7.2.3.2) - redis (>= 4.0.1) + redis (~> 5.0) rubocop (~> 1) tzinfo-data will_paginate (~> 4.0) diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index d5ebd2d..d42d7d7 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -6,12 +6,15 @@ class Attack redis_url = ENV['RACK_ATTACK_REDIS_URL'].presence || ENV['REDIS_URL'].presence Rack::Attack.cache.store = if redis_url - ActiveSupport::Cache::RedisCacheStore.new( - url: redis_url, - namespace: 'rack_attack' - ) - elsif Rails.env.production? - raise 'RACK_ATTACK_REDIS_URL or REDIS_URL is required in production' + begin + ActiveSupport::Cache::RedisCacheStore.new( + url: redis_url, + namespace: 'rack_attack' + ) + rescue StandardError => e + Rails.logger.warn("Rack::Attack: Redis failed (#{e.message}), using MemoryStore") + ActiveSupport::Cache::MemoryStore.new + end else ActiveSupport::Cache::MemoryStore.new end