Merge pull request #32573 from chloerei/fix-redis-store-clear-namespace

Fix redis store clear keys outside the namespace
This commit is contained in:
George Claghorn 2018-04-15 00:03:46 -04:00 committed by GitHub
commit d472229f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -286,7 +286,7 @@ module ActiveSupport
# Failsafe: Raises errors.
def clear(options = nil)
failsafe :clear do
if namespace = merged_options(options)[namespace]
if namespace = merged_options(options)[:namespace]
delete_matched "*", namespace: namespace
else
redis.with { |c| c.flushdb }

View File

@ -221,4 +221,22 @@ module ActiveSupport::Cache::RedisCacheStoreTests
end
end
end
class ClearTest < StoreTest
test "clear all cache key" do
@cache.write("foo", "bar")
@cache.write("fu", "baz")
@cache.clear
assert !@cache.exist?("foo")
assert !@cache.exist?("fu")
end
test "only clear namespace cache key" do
@cache.write("foo", "bar")
@cache.redis.set("fu", "baz")
@cache.clear
assert !@cache.exist?("foo")
assert @cache.redis.exists("fu")
end
end
end