From 64e953f674cf86801a25b8da80447a6c0869388f Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Fri, 27 Sep 2024 18:39:04 -0500 Subject: [PATCH] Updated RemoveByPrefix and added tests --- src/Foundatio.Redis/Cache/RedisCacheClient.cs | 3 ++- .../Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs | 6 ++++++ .../Caching/RedisHybridCacheClientTests.cs | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Foundatio.Redis/Cache/RedisCacheClient.cs b/src/Foundatio.Redis/Cache/RedisCacheClient.cs index bc286a7..5aa5ed2 100644 --- a/src/Foundatio.Redis/Cache/RedisCacheClient.cs +++ b/src/Foundatio.Redis/Cache/RedisCacheClient.cs @@ -101,7 +101,8 @@ public async Task RemoveAllAsync(IEnumerable keys = null) public async Task RemoveByPrefixAsync(string prefix) { const int chunkSize = 2500; - string regex = $"{prefix}*"; + string normalizedPrefix = String.IsNullOrWhiteSpace(prefix) ? "*" : prefix.Trim(); + string regex = normalizedPrefix.Contains("*") ? normalizedPrefix : $"{normalizedPrefix}*"; int total = 0; int index = 0; diff --git a/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs b/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs index a030257..5101d27 100644 --- a/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs +++ b/tests/Foundatio.Redis.Tests/Caching/RedisCacheClientTests.cs @@ -90,6 +90,12 @@ public override Task CanRemoveByPrefixAsync() return base.CanRemoveByPrefixAsync(); } + [Fact] + public override Task CanRemoveByPrefixWithScopedCachesAsync() + { + return base.CanRemoveByPrefixWithScopedCachesAsync(); + } + [Theory] [InlineData(50)] [InlineData(500)] diff --git a/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs b/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs index 66b96c3..4cf55b0 100644 --- a/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs +++ b/tests/Foundatio.Redis.Tests/Caching/RedisHybridCacheClientTests.cs @@ -50,6 +50,12 @@ public override Task CanRemoveByPrefixAsync() return base.CanRemoveByPrefixAsync(); } + [Fact] + public override Task CanRemoveByPrefixWithScopedCachesAsync() + { + return base.CanRemoveByPrefixWithScopedCachesAsync(); + } + [Theory] [InlineData(50)] [InlineData(500)]