aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2018-04-19 08:24:21 +0100
committerGitHub <noreply@github.com>2018-04-19 08:24:21 +0100
commitfb2af6f849c8d25732f2c17352c59f2dc8b8320d (patch)
tree9ea30543b6b2f68f15d9c0b711054ee035a4b8fe /activesupport/lib
parent7d25b651fa9011b040fab2f19fb315679519edb2 (diff)
parentef2af628a9ec1cc4e7b6997a021dd3f85cfe4665 (diff)
downloadrails-fb2af6f849c8d25732f2c17352c59f2dc8b8320d.tar.gz
rails-fb2af6f849c8d25732f2c17352c59f2dc8b8320d.tar.bz2
rails-fb2af6f849c8d25732f2c17352c59f2dc8b8320d.zip
Merge branch 'master' into fix-as-timezone-all
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/cache/redis_cache_store.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/cache/redis_cache_store.rb b/activesupport/lib/active_support/cache/redis_cache_store.rb
index 74f935e02e..11c574258f 100644
--- a/activesupport/lib/active_support/cache/redis_cache_store.rb
+++ b/activesupport/lib/active_support/cache/redis_cache_store.rb
@@ -62,8 +62,9 @@ module ActiveSupport
end
end
- DELETE_GLOB_LUA = "for i, name in ipairs(redis.call('KEYS', ARGV[1])) do redis.call('DEL', name); end"
- private_constant :DELETE_GLOB_LUA
+ # The maximum number of entries to receive per SCAN call.
+ SCAN_BATCH_SIZE = 1000
+ private_constant :SCAN_BATCH_SIZE
# Support raw values in the local cache strategy.
module LocalCacheWithRaw # :nodoc:
@@ -231,12 +232,18 @@ module ActiveSupport
# Failsafe: Raises errors.
def delete_matched(matcher, options = nil)
instrument :delete_matched, matcher do
- case matcher
- when String
- redis.with { |c| c.eval DELETE_GLOB_LUA, [], [namespace_key(matcher, options)] }
- else
+ unless String === matcher
raise ArgumentError, "Only Redis glob strings are supported: #{matcher.inspect}"
end
+ redis.with do |c|
+ pattern = namespace_key(matcher, options)
+ cursor = "0"
+ # Fetch keys in batches using SCAN to avoid blocking the Redis server.
+ begin
+ cursor, keys = c.scan(cursor, match: pattern, count: SCAN_BATCH_SIZE)
+ c.del(*keys) unless keys.empty?
+ end until cursor == "0"
+ end
end
end