Skip to content

Commit

Permalink
Merge branch 'main' into multiple-instances
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy authored Nov 21, 2023
2 parents 800160e + d9fedfa commit f343386
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/rack/attack/store_proxy/redis_cache_store_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ def self.handle?(store)
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
end

def increment(name, amount = 1, **options)
# RedisCacheStore#increment ignores options[:expires_in].
#
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
# the counter. After that we continue using the original RedisCacheStore#increment.
if options[:expires_in] && !read(name)
write(name, amount, options)
if defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR < 6
def increment(name, amount = 1, **options)
# RedisCacheStore#increment ignores options[:expires_in] in versions prior to 6.
#
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
# the counter. After that we continue using the original RedisCacheStore#increment.
if options[:expires_in] && !read(name)
write(name, amount, options)

amount
else
super
amount
else
super
end
end
end

Expand Down

0 comments on commit f343386

Please sign in to comment.