Merge pull request #38206 from tsuka/fix-38178

Fix NoMethodError on ActiveSupport::Cache::RedisCacheStore#clear with…
This commit is contained in:
Eileen M. Uchitelle 2020-01-13 11:56:01 -05:00 committed by GitHub
commit cdc3dce724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

@ -246,10 +246,14 @@ def delete_matched(matcher, options = nil)
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"
nodes = c.respond_to?(:nodes) ? c.nodes : [c]
nodes.each do |node|
begin
cursor, keys = node.scan(cursor, match: pattern, count: SCAN_BATCH_SIZE)
node.del(*keys) unless keys.empty?
end until cursor == "0"
end
end
end
end

@ -301,5 +301,16 @@ class ClearTest < StoreTest
assert_not @cache.exist?("foo")
assert @cache.redis.exists("fu")
end
test "clear all cache key with Redis::Distributed" do
cache = ActiveSupport::Cache::RedisCacheStore.new(
url: %w[redis://localhost:6379/0, redis://localhost:6379/1],
timeout: 0.1, namespace: @namespace, expires_in: 60, driver: DRIVER)
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.clear
assert_not cache.exist?("foo")
assert_not cache.exist?("fu")
end
end
end