From 8b60bf565eb475c13e39caa305c4415b34d8ec02 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 05 十二月 2025 08:49:19 +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 b97506c..76ad76d 100644
--- a/src/main/java/com/zy/common/utils/RedisUtil.java
+++ b/src/main/java/com/zy/common/utils/RedisUtil.java
@@ -100,6 +100,26 @@
return keys;
}
+ public Set<String> scanKeys(String key, int limit) {
+ return (Set<String>) redisTemplate.execute((org.springframework.data.redis.core.RedisCallback<Set<String>>) connection -> {
+ org.springframework.data.redis.core.ScanOptions options = org.springframework.data.redis.core.ScanOptions.scanOptions().match(key + "*").count(limit).build();
+ org.springframework.data.redis.core.Cursor<byte[]> cursor = connection.scan(options);
+ java.util.LinkedHashSet<String> result = new java.util.LinkedHashSet<>();
+ while (cursor.hasNext()) {
+ result.add(new String(cursor.next()));
+ if (result.size() >= limit) {
+ break;
+ }
+ }
+ try { cursor.close(); } catch (Exception e) {}
+ return result;
+ });
+ }
+
+ public java.util.List<Object> multiGet(java.util.Collection<String> keys) {
+ return redisTemplate.opsForValue().multiGet(keys);
+ }
+
/**
* 鏅�氱紦瀛樿幏鍙�
*
@@ -136,6 +156,24 @@
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);
--
Gitblit v1.9.1