File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
src/main/java/com/netease/lib/redistemplatetool/util Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 55
66 <groupId >com.netease.lowcode</groupId >
77 <artifactId >redis-template-tool</artifactId >
8- <version >1.0.0 </version >
8+ <version >1.0.1 </version >
99 <parent >
1010 <groupId >org.springframework.boot</groupId >
1111 <artifactId >spring-boot-starter-parent</artifactId >
4040 <artifactId >junit</artifactId >
4141 <scope >test</scope >
4242 </dependency >
43-
43+ <!-- 强制指定新版Commons Pool2 -->
44+ <dependency >
45+ <groupId >org.apache.commons</groupId >
46+ <artifactId >commons-pool2</artifactId >
47+ </dependency >
4448 </dependencies >
4549 <build >
4650 <plugins >
Original file line number Diff line number Diff line change 44import org .springframework .beans .factory .annotation .Autowired ;
55import org .springframework .data .redis .core .*;
66import org .springframework .stereotype .Component ;
7+ import org .springframework .util .CollectionUtils ;
8+ import org .springframework .util .StringUtils ;
79
810import java .util .*;
911import java .util .concurrent .TimeUnit ;
@@ -15,6 +17,34 @@ public class RedisTool {
1517 @ Autowired
1618 public RedisTemplate <String , String > redisTemplate ;
1719
20+ /**
21+ * 是否存在key,返回true/false
22+ *
23+ * @param key
24+ * @return
25+ */
26+ @ NaslLogic
27+ public Boolean hasKey (String key ) {
28+ if (StringUtils .isEmpty (key )) {
29+ return false ;
30+ }
31+ return redisTemplate .hasKey (key );
32+ }
33+
34+ /**
35+ * 批量删除key
36+ *
37+ * @param keys
38+ * @return
39+ */
40+ @ NaslLogic
41+ public Long deleteKeys (List <String > keys ) {
42+ if (CollectionUtils .isEmpty (keys )) {
43+ return 0L ;
44+ }
45+ return redisTemplate .delete (keys );
46+ }
47+
1848 /**
1949 * 设置 Redis 中指定 key 的过期时间
2050 *
You can’t perform that action at this time.
0 commit comments