Skip to content

Commit

Permalink
upgrade StackExchange.Redis to v2.8.0, add and implement redis copy m…
Browse files Browse the repository at this point in the history
…ethod into IRedisCachingProvider (#543)
  • Loading branch information
mjal146 authored Sep 9, 2024
1 parent 57e0bc8 commit 177bb4c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Keys.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace EasyCaching.CSRedis
using System;

namespace EasyCaching.CSRedis
{
using EasyCaching.Core;
using System.Collections.Generic;
Expand Down Expand Up @@ -56,6 +58,15 @@ public async Task<bool> KeyPersistAsync(string cacheKey)
return flag;
}

public bool KeyCopy(string sourceKey, string destinationKey, bool isReplace = false)
{
throw new NotSupportedException();
}

public Task<bool> KeyCopyAsync(string sourceKey, string destinationKey, bool isReplace = false)
{
throw new NotSupportedException();
}
public bool KeyExists(string cacheKey)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
Expand Down
24 changes: 24 additions & 0 deletions src/EasyCaching.Core/IRedisCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,36 @@ public interface IRedisCachingProvider
/// <param name="cacheKey"></param>
/// <returns></returns>
bool KeyPersist(string cacheKey);

/// <summary>
/// https://redis.io/commands/persist
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
Task<bool> KeyPersistAsync(string cacheKey);


/// <summary>
/// Copies the value from the <paramref name="sourceKey"/> to the specified <paramref name="destinationKey"/>.
/// </summary>
/// <param name="sourceKey">The key of the source value to copy.</param>
/// <param name="destinationKey">The destination key to copy the source to.</param>
/// <param name="isReplace">Whether to overwrite an existing values at <paramref name="destinationKey"/>. If <see langword="false"/> and the key exists, the copy will not succeed.</param>
/// <returns><see langword="true"/> if key was copied. <see langword="false"/> if key was not copied.</returns>
/// <remarks>https://redis.io/commands/copy</remarks>
bool KeyCopy(string sourceKey, string destinationKey, bool isReplace = false);


/// <summary>
/// Copies the value from the <paramref name="sourceKey"/> to the specified <paramref name="destinationKey"/>.
/// </summary>
/// <param name="sourceKey">The key of the source value to copy.</param>
/// <param name="destinationKey">The destination key to copy the source to.</param>
/// <param name="isReplace">Whether to overwrite an existing values at <paramref name="destinationKey"/>. If <see langword="false"/> and the key exists, the copy will not succeed.</param>
/// <returns><see langword="true"/> if key was copied. <see langword="false"/> if key was not copied.</returns>
/// <remarks>https://redis.io/commands/copy</remarks>
Task<bool> KeyCopyAsync(string sourceKey, string destinationKey, bool isReplace = false);

/// <summary>
///
/// </summary>
Expand Down
20 changes: 19 additions & 1 deletion src/EasyCaching.Redis/DefaultRedisCachingProvider.Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public bool KeyPersist(string cacheKey)
var flag = _cache.KeyPersist(cacheKey);
return flag;
}

public async Task<bool> KeyPersistAsync(string cacheKey)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
Expand All @@ -62,6 +62,24 @@ public async Task<bool> KeyPersistAsync(string cacheKey)
return flag;
}

public bool KeyCopy(string sourceKey, string destinationKey, bool isReplace = false)
{
ArgumentCheck.NotNullOrWhiteSpace(sourceKey, nameof(sourceKey));
ArgumentCheck.NotNullOrWhiteSpace(destinationKey, nameof(destinationKey));

var flag = _cache.KeyCopy(sourceKey,destinationKey,_cache.Database,isReplace);
return flag;
}

public async Task<bool> KeyCopyAsync(string sourceKey, string destinationKey, bool isReplace = false)
{
ArgumentCheck.NotNullOrWhiteSpace(sourceKey, nameof(sourceKey));
ArgumentCheck.NotNullOrWhiteSpace(destinationKey, nameof(destinationKey));

var flag = await _cache.KeyCopyAsync(sourceKey,destinationKey,_cache.Database,isReplace);
return flag;
}

public bool KeyExists(string cacheKey)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
Expand Down
2 changes: 1 addition & 1 deletion src/EasyCaching.Redis/EasyCaching.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.7.33" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EasyCaching.Core\EasyCaching.Core.csproj" />
Expand Down

0 comments on commit 177bb4c

Please sign in to comment.