Skip to content

Commit

Permalink
🐛 Fix bug for prefix handle in redis caching provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
catcherwong committed Feb 1, 2018
1 parent 9c72281 commit fdc615c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/EasyCaching.Redis/DefaultRedisCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public CacheValue<T> Get<T>(string cacheKey) where T : class
else
{
return CacheValue<T>.NoValue;
}
}
}

/// <summary>
Expand All @@ -162,7 +162,7 @@ public async Task<CacheValue<T>> GetAsync<T>(string cacheKey) where T : class
else
{
return CacheValue<T>.NoValue;
}
}
}

/// <summary>
Expand Down Expand Up @@ -251,7 +251,7 @@ public async Task<bool> ExistsAsync(string cacheKey)
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));

return await _cache.KeyExistsAsync(cacheKey);
}
}

/// <summary>
/// Refresh the specified cacheKey, cacheValue and expiration.
Expand Down Expand Up @@ -312,7 +312,7 @@ public async Task RemoveByPrefixAsync(string prefix)
{
ArgumentCheck.NotNullOrWhiteSpace(prefix, nameof(prefix));

this.HandlePrefix(prefix);
prefix = this.HandlePrefix(prefix);

foreach (var server in _servers)
{
Expand Down Expand Up @@ -368,28 +368,26 @@ private async Task HandleKeyDelWithTranAsync(IServer server, string prefix)
}
while (count <= 0);
}

/// <summary>
/// Handles the prefix of CacheKey.
/// </summary>
/// <param name="prefix">Prefix of CacheKey.</param>
/// <exception cref="ArgumentException">
private void HandlePrefix(string prefix)
private string HandlePrefix(string prefix)
{
// Forbid
if (prefix.Equals("*"))
{
throw new ArgumentException("the prefix should not to *");
}

// Don't start with *
prefix = new System.Text.RegularExpressions.Regex("^\\*+").Replace(prefix, "");

// End with *
if (!prefix.EndsWith("*", StringComparison.OrdinalIgnoreCase))
{
prefix = string.Concat(prefix, "*");
}

return prefix;
}
}
}

0 comments on commit fdc615c

Please sign in to comment.