mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix NoMethodError on ActiveSupport::Cache::RedisCacheStore#clear with Redis::Distributed
This commit is contained in:
parent
7abcba6909
commit
fd2bc5cee6
2 changed files with 19 additions and 4 deletions
|
@ -246,13 +246,17 @@ module ActiveSupport
|
||||||
pattern = namespace_key(matcher, options)
|
pattern = namespace_key(matcher, options)
|
||||||
cursor = "0"
|
cursor = "0"
|
||||||
# Fetch keys in batches using SCAN to avoid blocking the Redis server.
|
# Fetch keys in batches using SCAN to avoid blocking the Redis server.
|
||||||
|
nodes = c.respond_to?(:nodes) ? c.nodes : [c]
|
||||||
|
|
||||||
|
nodes.each do |node|
|
||||||
begin
|
begin
|
||||||
cursor, keys = c.scan(cursor, match: pattern, count: SCAN_BATCH_SIZE)
|
cursor, keys = node.scan(cursor, match: pattern, count: SCAN_BATCH_SIZE)
|
||||||
c.del(*keys) unless keys.empty?
|
node.del(*keys) unless keys.empty?
|
||||||
end until cursor == "0"
|
end until cursor == "0"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Cache Store API implementation.
|
# Cache Store API implementation.
|
||||||
#
|
#
|
||||||
|
|
|
@ -301,5 +301,16 @@ module ActiveSupport::Cache::RedisCacheStoreTests
|
||||||
assert_not @cache.exist?("foo")
|
assert_not @cache.exist?("foo")
|
||||||
assert @cache.redis.exists("fu")
|
assert @cache.redis.exists("fu")
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue