Skip to content

Commit f343386

Browse files
authored
Merge branch 'main' into multiple-instances
2 parents 800160e + d9fedfa commit f343386

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/rack/attack/store_proxy/redis_cache_store_proxy.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ def self.handle?(store)
1010
store.class.name == "ActiveSupport::Cache::RedisCacheStore"
1111
end
1212

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

21-
amount
22-
else
23-
super
22+
amount
23+
else
24+
super
25+
end
2426
end
2527
end
2628

0 commit comments

Comments
 (0)