Skip to content

Commit 64051a4

Browse files
committed
Fix RemoveAll for clusters
1 parent 105a139 commit 64051a4

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/Foundatio.Redis/Cache/RedisCacheClient.cs

+20-8
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,25 @@ public async Task<int> RemoveAllAsync(IEnumerable<string> keys = null)
9191
else
9292
{
9393
var redisKeys = keys.Where(k => !String.IsNullOrEmpty(k)).Select(k => (RedisKey)k).ToArray();
94-
if (redisKeys.Length > 0)
95-
return (int)await Database.KeyDeleteAsync(redisKeys).AnyContext();
94+
if (redisKeys.Length <= 0)
95+
return 0;
96+
97+
int count = 0;
98+
foreach (var key in redisKeys)
99+
{
100+
try
101+
{
102+
if (await Database.KeyDeleteAsync(key).AnyContext())
103+
count++;
104+
}
105+
catch (Exception ex)
106+
{
107+
if (_logger.IsEnabled(LogLevel.Error))
108+
_logger.LogError(ex, "Unable to delete key {Key}", key);
109+
}
110+
}
111+
112+
return count;
96113
}
97114

98115
return 0;
@@ -111,12 +128,7 @@ public async Task<int> RemoveByPrefixAsync(string prefix)
111128

112129
while (keys.Length != 0 || index < chunkSize)
113130
{
114-
foreach (string key in keys)
115-
{
116-
bool success = await RemoveAsync(key).AnyContext();
117-
if (success)
118-
total++;
119-
}
131+
total += await RemoveAllAsync(keys).AnyContext();
120132

121133
index += chunkSize;
122134
(cursor, keys) = await ScanKeysAsync(regex, cursor, chunkSize).AnyContext();

0 commit comments

Comments
 (0)