From eb77373d92f01e51b98bda8fae66315ed9a4394d Mon Sep 17 00:00:00 2001
From: 彭雪彬 <1724387007@qq.com>
Date: Mon, 14 Jul 2025 17:08:57 +0800
Subject: [PATCH] 骑手接单和骑手取消订单

---
 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