소스 검색

add 增加 RedisUtils 工具 hasKey 检查key存在方法

疯狂的狮子li 3 년 전
부모
커밋
c526ab1870
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java

+ 10 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java

@@ -376,4 +376,14 @@ public class RedisUtils {
         Iterable<String> iterable = CLIENT.getKeys().getKeysByPattern(pattern);
         return IterUtil.toList(iterable);
     }
+
+    /**
+     * 检查redis中是否存在key
+     *
+     * @param key 键
+     */
+    public static Boolean hasKey(String key) {
+        RKeys rKeys = CLIENT.getKeys();
+        return rKeys.countExists(key) > 0;
+    }
 }