|
@@ -0,0 +1,44 @@
|
|
|
+package com.css.simulation.resource.scheduler.common.configuration.redis;
|
|
|
+
|
|
|
+import api.common.util.CollectionUtil;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class CustomRedisClient {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
+ public void deleteByKey(String key) {
|
|
|
+ stringRedisTemplate.delete(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByKeyCollection(Collection<String> keyCollection) {
|
|
|
+ stringRedisTemplate.delete(keyCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteByPrefix(String prefix) {
|
|
|
+ Set<String> keySetByPrefix = getKeySetByPrefix(prefix);
|
|
|
+ deleteByKeyCollection(keySetByPrefix);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getStringByKey(String key) {
|
|
|
+ return stringRedisTemplate.opsForValue().get(key);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Set<String> getKeySetByPrefix(String prefix) {
|
|
|
+ return stringRedisTemplate.keys(prefix + "*");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void flushdb() {
|
|
|
+ Set<String> keys = stringRedisTemplate.keys("*");
|
|
|
+ if (CollectionUtil.isNotEmpty(keys)) {
|
|
|
+ stringRedisTemplate.delete(keys);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|