|
@@ -0,0 +1,53 @@
|
|
|
+package com.diagbot.util;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description:
|
|
|
+ * @author: zhoutg
|
|
|
+ * @time: 2020/8/11 19:52
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class RedisUtil {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("redisTemplateForSimilar")
|
|
|
+ RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定类型的数据
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, String> getValueByType(List<String> list, String type) {
|
|
|
+ Map<String, String> res = new LinkedHashMap<>();
|
|
|
+ Map<String, String> map = (Map<String, String>)redisTemplate.opsForValue().get(type);
|
|
|
+ if (map == null) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ for (String str : list) {
|
|
|
+ res.put(str, map.get(str) == null ? "" : map.get(str));
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新指定类型下的数据
|
|
|
+ *
|
|
|
+ * @param map
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+ public void updateValueByType(Map<String, String> map, String type) {
|
|
|
+ redisTemplate.opsForValue().set(type, map);
|
|
|
+ }
|
|
|
+}
|