Skip to content

Commit 134ba78

Browse files
authored
Merge pull request #300 from JiazhenBao/main
支持lettuce配置;提供hasKey和deleteKeys方法
2 parents e0e57e0 + a27a099 commit 134ba78

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

redis-template-tool/pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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>
@@ -40,7 +40,11 @@
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>

redis-template-tool/src/main/java/com/netease/lib/redistemplatetool/util/RedisTool.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.data.redis.core.*;
66
import org.springframework.stereotype.Component;
7+
import org.springframework.util.CollectionUtils;
8+
import org.springframework.util.StringUtils;
79

810
import java.util.*;
911
import 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
*

0 commit comments

Comments
 (0)