From 7278264f027d62664a0209699d0f66a22fd06a8e Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 13 四月 2026 10:24:04 +0800
Subject: [PATCH] feat: 更新依赖版本并优化MES接口调用

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Cache/RedisCacheService.cs |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Cache/RedisCacheService.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Cache/RedisCacheService.cs
index f52aa42..f52cc84 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Cache/RedisCacheService.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_RedisService/Cache/RedisCacheService.cs
@@ -365,6 +365,34 @@
             return Db.StringSet(fullKey, newJson, expiry, When.Exists);
         }
 
+        public bool TrySafeUpdate<T>(
+            string key,
+            T newValue,
+            object? expectedVersion,
+            Func<T, object?> versionExtractor,
+            int expireSeconds = -1) where T : class
+        {
+            var fullKey = BuildKey(key);
+            var existing = Db.StringGet(fullKey);
+            if (existing.IsNullOrEmpty) return false;
+
+            // 鍙嶅簭鍒楀寲鐜版湁鍊�
+            var existingValue = _serializer.Deserialize<T>(existing.ToString()!);
+            if (existingValue == null) return false;
+
+            // 妫�鏌ョ増鏈槸鍚﹀尮閰�
+            var currentVersion = versionExtractor(existingValue);
+            if (!Equals(currentVersion, expectedVersion))
+            {
+                return false; // 鐗堟湰涓嶅尮閰嶏紝鎷掔粷鏇存柊
+            }
+
+            // 鐗堟湰鍖归厤锛屾墽琛屾洿鏂�
+            var newJson = _serializer.Serialize(newValue);
+            var expiry = expireSeconds > 0 ? TimeSpan.FromSeconds(expireSeconds) : (TimeSpan?)null;
+            return Db.StringSet(fullKey, newJson, expiry, When.Exists);
+        }
+
         public string GetOrAdd(string key, string value, int expireSeconds = -1)
         {
             var fullKey = BuildKey(key);

--
Gitblit v1.9.3