From 177bb4cd4e524bb128533be358ea280282893bb9 Mon Sep 17 00:00:00 2001 From: Mohammad javad Akbari Date: Mon, 9 Sep 2024 05:19:07 +0330 Subject: [PATCH] upgrade StackExchange.Redis to v2.8.0, add and implement redis copy method into IRedisCachingProvider (#543) --- .../DefaultCSRedisCachingProvider.Keys.cs | 13 +++++++++- src/EasyCaching.Core/IRedisCachingProvider.cs | 24 +++++++++++++++++++ .../DefaultRedisCachingProvider.Keys.cs | 20 +++++++++++++++- .../EasyCaching.Redis.csproj | 2 +- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Keys.cs b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Keys.cs index a8cc945e..be63fdc1 100755 --- a/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Keys.cs +++ b/src/EasyCaching.CSRedis/DefaultCSRedisCachingProvider.Keys.cs @@ -1,4 +1,6 @@ -namespace EasyCaching.CSRedis +using System; + +namespace EasyCaching.CSRedis { using EasyCaching.Core; using System.Collections.Generic; @@ -56,6 +58,15 @@ public async Task KeyPersistAsync(string cacheKey) return flag; } + public bool KeyCopy(string sourceKey, string destinationKey, bool isReplace = false) + { + throw new NotSupportedException(); + } + + public Task KeyCopyAsync(string sourceKey, string destinationKey, bool isReplace = false) + { + throw new NotSupportedException(); + } public bool KeyExists(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); diff --git a/src/EasyCaching.Core/IRedisCachingProvider.cs b/src/EasyCaching.Core/IRedisCachingProvider.cs index fc5b6beb..e32d20ad 100644 --- a/src/EasyCaching.Core/IRedisCachingProvider.cs +++ b/src/EasyCaching.Core/IRedisCachingProvider.cs @@ -47,12 +47,36 @@ public interface IRedisCachingProvider /// /// bool KeyPersist(string cacheKey); + /// /// https://redis.io/commands/persist /// /// /// Task KeyPersistAsync(string cacheKey); + + + /// + /// Copies the value from the to the specified . + /// + /// The key of the source value to copy. + /// The destination key to copy the source to. + /// Whether to overwrite an existing values at . If and the key exists, the copy will not succeed. + /// if key was copied. if key was not copied. + /// https://redis.io/commands/copy + bool KeyCopy(string sourceKey, string destinationKey, bool isReplace = false); + + + /// + /// Copies the value from the to the specified . + /// + /// The key of the source value to copy. + /// The destination key to copy the source to. + /// Whether to overwrite an existing values at . If and the key exists, the copy will not succeed. + /// if key was copied. if key was not copied. + /// https://redis.io/commands/copy + Task KeyCopyAsync(string sourceKey, string destinationKey, bool isReplace = false); + /// /// /// diff --git a/src/EasyCaching.Redis/DefaultRedisCachingProvider.Keys.cs b/src/EasyCaching.Redis/DefaultRedisCachingProvider.Keys.cs index 143d8ad4..c166eac1 100755 --- a/src/EasyCaching.Redis/DefaultRedisCachingProvider.Keys.cs +++ b/src/EasyCaching.Redis/DefaultRedisCachingProvider.Keys.cs @@ -53,7 +53,7 @@ public bool KeyPersist(string cacheKey) var flag = _cache.KeyPersist(cacheKey); return flag; } - + public async Task KeyPersistAsync(string cacheKey) { ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey)); @@ -62,6 +62,24 @@ public async Task 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 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)); diff --git a/src/EasyCaching.Redis/EasyCaching.Redis.csproj b/src/EasyCaching.Redis/EasyCaching.Redis.csproj index 8c2264be..d096c658 100644 --- a/src/EasyCaching.Redis/EasyCaching.Redis.csproj +++ b/src/EasyCaching.Redis/EasyCaching.Redis.csproj @@ -33,7 +33,7 @@ - +