diff --git a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisLockUtils.java b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisLockUtils.java index 92d48e03..2768e073 100644 --- a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisLockUtils.java +++ b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisLockUtils.java @@ -25,9 +25,10 @@ import top.continew.starter.core.util.SpringUtils; import java.util.concurrent.TimeUnit; /** - * Redisson分布式锁 工具类 + * Redisson 分布式锁工具类 * * @author lishuyan + * @since 2.13.4 */ public class RedisLockUtils implements AutoCloseable { diff --git a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java index 335e06ad..b5f3d873 100644 --- a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java +++ b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java @@ -26,8 +26,6 @@ import java.time.Duration; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; /** @@ -52,42 +50,6 @@ public class RedisUtils { return CLIENT; } - /** - * 发布消息 - * - * @param name 主题名称 - * @param msg 发送数据 - * @param consumer 自定义处理 - */ - public static void publish(String name, T msg, Consumer consumer) { - RTopic topic = CLIENT.getTopic(name); - topic.publish(msg); - consumer.accept(msg); - } - - /** - * 发布消息 - * - * @param name 主题名称 - * @param msg 发送数据 - */ - public static void publish(String name, T msg) { - RTopic topic = CLIENT.getTopic(name); - topic.publish(msg); - } - - /** - * 订阅消息 - * - * @param name 主题名称 - * @param clazz 消息类型 - * @param consumer 自定义处理 - */ - public static void subscribe(String name, Class clazz, Consumer consumer) { - RTopic topic = CLIENT.getTopic(name); - topic.addListener(clazz, (channel, msg) -> consumer.accept(msg)); - } - /** * 设置缓存 * @@ -559,77 +521,45 @@ public class RedisUtils { } /** - * 尝试获取锁 + * 发布消息 * - * @param key 键 - * @param expireTime 锁过期时间(单位:毫秒) - * @param timeout 获取锁超时时间(单位:毫秒) - * @return true:成功;false:失败 - * @since 2.7.2 + * @param name 主题名称 + * @param msg 发送数据 + * @param consumer 自定义处理 + * @author lishuyan + * @since 2.13.4 */ - public static boolean tryLock(String key, long expireTime, long timeout) { - return tryLock(key, expireTime, timeout, TimeUnit.MILLISECONDS); + public static void publish(String name, T msg, Consumer consumer) { + RTopic topic = CLIENT.getTopic(name); + topic.publish(msg); + consumer.accept(msg); } /** - * 释放锁 + * 发布消息 * - * @param key 键 - * @return true:释放成功;false:释放失败 - * @since 2.7.2 + * @param name 主题名称 + * @param msg 发送数据 + * @author lishuyan + * @since 2.13.4 */ - public static boolean unlock(String key) { - RLock lock = getLock(key); - return unlock(lock); + public static void publish(String name, T msg) { + RTopic topic = CLIENT.getTopic(name); + topic.publish(msg); } /** - * 尝试获取锁 + * 订阅消息 * - * @param key 键 - * @param expireTime 锁过期时间 - * @param timeout 获取锁超时时间 - * @param unit 时间单位 - * @return true:成功;false:失败 - * @since 2.7.2 + * @param name 主题名称 + * @param clazz 消息类型 + * @param consumer 自定义处理 + * @author lishuyan + * @since 2.13.4 */ - public static boolean tryLock(String key, long expireTime, long timeout, TimeUnit unit) { - RLock lock = getLock(key); - try { - return lock.tryLock(timeout, expireTime, unit); - } catch (InterruptedException e) { - return false; - } - } - - /** - * 释放锁 - * - * @param lock 锁实例 - * @return true:释放成功;false:释放失败 - * @since 2.7.2 - */ - public static boolean unlock(RLock lock) { - if (lock.isHeldByCurrentThread()) { - try { - lock.unlockAsync().get(); - return true; - } catch (ExecutionException | InterruptedException e) { - return false; - } - } - return false; - } - - /** - * 获取锁实例 - * - * @param key 键 - * @return 锁实例 - * @since 2.7.2 - */ - public static RLock getLock(String key) { - return CLIENT.getLock(key); + public static void subscribe(String name, Class clazz, Consumer consumer) { + RTopic topic = CLIENT.getTopic(name); + topic.addListener(clazz, (channel, msg) -> consumer.accept(msg)); } /**