From f655f06871961830739ac07ae731b2dbc8b0372f Mon Sep 17 00:00:00 2001 From: Ranyunqiao <2499115710@qq.com> Date: Thu, 11 Jun 2026 13:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/core/common/core/redis/RedisCache.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/healthlink-his-server/core-common/src/main/java/com/core/common/core/redis/RedisCache.java b/healthlink-his-server/core-common/src/main/java/com/core/common/core/redis/RedisCache.java index aa3c12e36..9a43f0c14 100755 --- a/healthlink-his-server/core-common/src/main/java/com/core/common/core/redis/RedisCache.java +++ b/healthlink-his-server/core-common/src/main/java/com/core/common/core/redis/RedisCache.java @@ -1,6 +1,7 @@ package com.core.common.core.redis; import com.core.common.exception.UtilException; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.HashOperations; @@ -18,6 +19,7 @@ import java.util.concurrent.TimeUnit; **/ @SuppressWarnings(value = {"unchecked", "rawtypes"}) @Component +@Slf4j public class RedisCache { @Autowired public RedisTemplate redisTemplate; @@ -94,8 +96,20 @@ public class RedisCache { * @return 缓存键值对应的数据 */ public T getCacheObject(final String key) { - ValueOperations operation = redisTemplate.opsForValue(); - return operation.get(key); + try { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } catch (Exception e) { + log.error("Redis获取对象异常, key: {}, 错误信息: {}", key, e.getMessage()); + // 如果发生序列化等异常,可能是旧版本数据或损坏数据,直接删除以防止程序崩溃 + try { + redisTemplate.delete(key); + log.info("已自动清理损坏的缓存Key: {}", key); + } catch (Exception ex) { + log.error("自动清理损坏缓存失败, key: {}", key, ex); + } + return null; + } } /**