diff --git a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisQueueUtils.java b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisQueueUtils.java deleted file mode 100644 index d9226fcb..00000000 --- a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisQueueUtils.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.starter.cache.redisson.util; - -import cn.hutool.extra.spring.SpringUtil; -import org.redisson.api.*; - -import java.util.concurrent.TimeUnit; - -/** - * Redis 队列工具类 - * - * @author Charles7c - * @since 2.12.1 - */ -public class RedisQueueUtils { - - private static final RedissonClient CLIENT = SpringUtil.getBean(RedissonClient.class); - - private RedisQueueUtils() { - } - - /** - * 获取 Redisson 客户端实例 - * - * @return Redisson 客户端实例 - */ - public static RedissonClient getClient() { - return CLIENT; - } - - /** - * 获取阻塞队列实例 - * - * @param key 键 - * @return 阻塞队列实例 - */ - public static RBlockingQueue getBlockingQueue(String key) { - return CLIENT.getBlockingQueue(key); - } - - /** - * 添加元素到阻塞队列尾部 - *

- * 如果队列已满,则返回 false - *

- * - * @param key 键 - * @param value 值 - * @return true:添加成功;false:添加失败 - */ - public static boolean addBlockingQueueData(String key, T value) { - RBlockingQueue queue = getBlockingQueue(key); - return queue.offer(value); - } - - /** - * 获取并移除阻塞队列头部元素 - *

- * 如果队列为空,则返回 null - *

- * - * @param key 键 - * @return 队列头部元素,如果队列为空,则返回 null - */ - public static T getBlockingQueueData(String key) { - RBlockingQueue queue = getBlockingQueue(key); - return queue.poll(); - } - - /** - * 删除阻塞队列中的指定元素 - * - * @param key 键 - * @param value 值 - * @return true:删除成功;false:删除失败 - */ - public static boolean removeBlockingQueueData(String key, T value) { - RBlockingQueue queue = getBlockingQueue(key); - return queue.remove(value); - } - - /** - * 获取延迟队列实例 - * - * @param key 键 - * @return 延迟队列实例 - */ - public static RDelayedQueue getDelayedQueue(String key) { - RBlockingQueue blockingQueue = getBlockingQueue(key); - return CLIENT.getDelayedQueue(blockingQueue); - } - - /** - * 添加元素到延迟队列 - * - * @param key 键 - * @param value 值 - * @param delay 延迟时间 - * @param unit 时间单位 - */ - public static void addDelayedQueueData(String key, T value, long delay, TimeUnit unit) { - RDelayedQueue delayedQueue = getDelayedQueue(key); - delayedQueue.offer(value, delay, unit); - } - - /** - * 获取并移除延迟队列头部元素 - *

- * 如果队列为空,则返回 null - *

- * - * @param key 键 - * @return 队列头部元素,如果队列为空,则返回 null - */ - public static T getDelayedQueueData(String key) { - RDelayedQueue delayedQueue = getDelayedQueue(key); - return delayedQueue.poll(); - } - - /** - * 移除延迟队列中的指定元素 - * - * @param key 键 - * @param value 值 - * @return true:移除成功;false:移除失败 - */ - public static boolean removeDelayedQueueData(String key, T value) { - RDelayedQueue delayedQueue = getDelayedQueue(key); - return delayedQueue.remove(value); - } -} 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 28b4927a..b522441f 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 @@ -263,6 +263,75 @@ public class RedisUtils { return CLIENT.getKeys().getKeysStream(options).toList(); } + /** + * 设置 Hash 中指定字段的值 + * + * @param key Hash 键 + * @param field 字段 + * @param value 值 + * @author KAI + * @since 2.13.4 + */ + public static void hSet(String key, String field, T value) { + RMap map = CLIENT.getMap(key); + map.put(field, value); + } + + /** + * 获取 Hash 中指定字段的值 + * + * @param key Hash 键 + * @param field 字段 + * @return 值 + * @author KAI + * @since 2.13.4 + */ + public static T hGet(String key, String field) { + RMap map = CLIENT.getMap(key); + return map.get(field); + } + + /** + * 获取整个 Hash 的所有字段值 + * + * @param key Hash 键 + * @return Map + * @author KAI + * @since 2.13.4 + */ + public static Map hGetAll(String key) { + RMap map = CLIENT.getMap(key); + return map.readAllMap(); + } + + /** + * 判断 Hash 中是否存在指定字段 + * + * @param key Hash 键 + * @param field 字段 + * @return true:存在;false:不存在 + * @author KAI + * @since 2.13.4 + */ + public static boolean hExists(String key, String field) { + RMap map = CLIENT.getMap(key); + return map.containsKey(field); + } + + /** + * 删除 Hash 中指定字段 + * + * @param key Hash 键 + * @param fields 字段数组 + * @return 删除成功的字段数量 + * @author KAI + * @since 2.13.4 + */ + public static long hDel(String key, String... fields) { + RMap map = CLIENT.getMap(key); + return map.fastRemove(fields); + } + /** * 添加元素到 ZSet 中 * @@ -535,68 +604,4 @@ public class RedisUtils { public static String formatKey(String... subKeys) { return String.join(StringConstants.COLON, ArrayUtil.removeBlank(subKeys)); } - - /** - * 设置 Hash 中指定字段的值 - * - * @param key Hash 键 - * @param field 字段 - * @param value 值 - * @since 2.13.4 - */ - public static void hSet(String key, String field, T value) { - RMap map = CLIENT.getMap(key); - map.put(field, value); - } - - /** - * 获取 Hash 中指定字段的值 - * - * @param key Hash 键 - * @param field 字段 - * @return 值 - * @since 2.13.4 - */ - public static T hGet(String key, String field) { - RMap map = CLIENT.getMap(key); - return map.get(field); - } - - /** - * 获取整个 Hash 的所有字段值 - * - * @param key Hash 键 - * @return Map - * @since 2.13.4 - */ - public static Map hGetAll(String key) { - RMap map = CLIENT.getMap(key); - return map.readAllMap(); - } - - /** - * 判断 Hash 中是否存在指定字段 - * - * @param key Hash 键 - * @param field 字段 - * @return true:存在;false:不存在 - * @since 2.13.4 - */ - public static boolean hExists(String key, String field) { - RMap map = CLIENT.getMap(key); - return map.containsKey(field); - } - - /** - * 删除 Hash 中指定字段 - * - * @param key Hash 键 - * @param fields 字段数组 - * @return 删除成功的字段数量 - * @since 2.13.4 - */ - public static long hDel(String key, String... fields) { - RMap map = CLIENT.getMap(key); - return map.fastRemove(fields); - } }