From 3c45d4f9f3aba5bc85a9577e43c0dffc71b93a22 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 10 七月 2025 15:54:27 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/RedisUtil.java |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 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 85e4a0a..b97506c 100644
--- a/src/main/java/com/zy/common/utils/RedisUtil.java
+++ b/src/main/java/com/zy/common/utils/RedisUtil.java
@@ -1,11 +1,13 @@
 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;
 import org.springframework.util.CollectionUtils;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -23,6 +25,9 @@
 
     @Autowired
     private RedisTemplate redisTemplate;
+
+    @Autowired
+    private StringRedisTemplate stringRedisTemplate;
 
     public RedisUtil(RedisTemplate redisTemplate) {
         this.redisTemplate = redisTemplate;
@@ -90,6 +95,11 @@
 
     //============================ String =============================
 
+    public Set<String> searchKeys(String key) {
+        Set<String> keys = redisTemplate.keys(key + "*");
+        return keys;
+    }
+
     /**
      * 鏅�氱紦瀛樿幏鍙�
      *
@@ -98,6 +108,21 @@
      */
     public Object get(String key) {
         return key == null ? null : redisTemplate.opsForValue().get(key);
+    }
+
+    /**
+     * 鑾峰彇鍏ㄩ儴鏁版嵁
+     * @return
+     */
+    public HashMap<Object, Object> getRedis() {
+        Set<String> keys = redisTemplate.keys("*");
+        HashMap<Object, Object> map = new HashMap<>();
+        for (String key : keys) {
+            Object value = redisTemplate.opsForValue().get(key);
+            map.put(key, value);
+        }
+
+        return map;//杩斿洖鍏ㄩ儴鏁版嵁闆嗗悎
     }
 
     /**
@@ -110,6 +135,18 @@
     public boolean set(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);
+                if (o == null) {
+                    continue;
+                }
+
+                if (o.equals(value)) {
+                    break;
+                }
+            }
             return true;
         } catch (Exception e) {
             e.printStackTrace();
@@ -132,6 +169,7 @@
             } else {
                 set(key, value);
             }
+            redisTemplate.execute((RedisCallback<Void>) connection -> null);
             return true;
         } catch (Exception e) {
             e.printStackTrace();

--
Gitblit v1.9.1