From 8c7b4949dfcf875cc537304d34a7f6960cbb0c10 Mon Sep 17 00:00:00 2001
From: qlsxk <qlsxk@qq.com>
Date: 星期四, 16 十月 2025 14:57:12 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/utils/RedisUtil.java | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/common/utils/RedisUtil.java b/src/main/java/com/zy/common/utils/RedisUtil.java
index ba150e5..80b4f9a 100644
--- a/src/main/java/com/zy/common/utils/RedisUtil.java
+++ b/src/main/java/com/zy/common/utils/RedisUtil.java
@@ -1,6 +1,7 @@
package com.zy.common.utils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
@@ -134,6 +135,25 @@
public boolean set(String key, Object value) {
try {
redisTemplate.opsForValue().set(key, value);
+ redisTemplate.execute((RedisCallback<Void>) connection -> null);
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 鏅�氱紦瀛樻斁鍏�
+ *
+ * @param key 閿�
+ * @param value 鍊�
+ * @return true鎴愬姛 false澶辫触
+ */
+ public boolean setSync(String key, Object value) {
+ try {
+ redisTemplate.opsForValue().set(key, value);
+ redisTemplate.execute((RedisCallback<Void>) connection -> null);
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 10000) {//鏈夋晥鏈�10s
Object o = redisTemplate.opsForValue().get(key);
@@ -167,6 +187,7 @@
} else {
set(key, value);
}
+ redisTemplate.execute((RedisCallback<Void>) connection -> null);
return true;
} catch (Exception e) {
e.printStackTrace();
--
Gitblit v1.9.1