Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade StackExchange.Redis to v2.8.0, add and implement Redis COPY #543

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading