From a5a0a3c29a97c807cda8846994d1d8df6adeb9e5 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Mon, 14 Jul 2025 21:09:57 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/pxb' into xin

---
 oying-common/src/main/java/com/oying/utils/RedisUtils.java |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/oying-common/src/main/java/com/oying/utils/RedisUtils.java b/oying-common/src/main/java/com/oying/utils/RedisUtils.java
index 4467f18..361c573 100644
--- a/oying-common/src/main/java/com/oying/utils/RedisUtils.java
+++ b/oying-common/src/main/java/com/oying/utils/RedisUtils.java
@@ -392,6 +392,27 @@
         }
     }
 
+    /**
+     * 分布式ID生成器
+     *
+     * @param key   键
+     * @param value 值
+     * @param time  时间(秒) time要大于0 如果time小于等于0 将设置无限期,注意:这里将会替换原有的时间
+     * @return true成功 false 失败
+     */
+    public boolean setIfAbsent(String key, Object value, long time) {
+        try {
+            if (time > 0) {
+                Boolean result = redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS);
+                return result;
+            } else {
+                return false;
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return false;
+        }
+    }
     // ================================Map=================================
 
     /**

--
Gitblit v1.9.3