Browse Source

更新工具类

zhoutg 3 năm trước cách đây
mục cha
commit
4a55ed6ef1
1 tập tin đã thay đổi với 6 bổ sung25 xóa
  1. 6 25
      src/main/java/com/diagbot/util/RedisUtil.java

+ 6 - 25
src/main/java/com/diagbot/util/RedisUtil.java

@@ -11,10 +11,8 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.SessionCallback;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -95,21 +93,6 @@ public class RedisUtil {
         redisTemplate.opsForValue().multiSet(map);
     }
 
-    public <T> List<Map<String, T>> divideByCopies(Map<String, T> originList, int num) {
-        List<Map<String, T>> list = new ArrayList<>();
-        if (originList == null || originList.isEmpty() || num < 0) {
-            return null;
-        }
-        for (int i = 0; i < num; i++) {
-            list.add(new LinkedHashMap<>());
-        }
-        int j  = 0;
-        for (String key : originList.keySet()) {
-            list.get(j % num).put(key, originList.get(key));
-        }
-        return list;
-    }
-
     /**
      * 根据正则key获取value列表
      *
@@ -279,30 +262,28 @@ public class RedisUtil {
         return redisTemplate.renameIfAbsent(oldKey, newKey);
     }
 
-    /** -------------------string相关操作--------------------- */
-
     /**
      * 将值 value 关联到 key ,并将 key 的过期时间设为 timeout
      *
      * @param key
-     * @param value
+     * @param t
      * @param timeout 过期时间
      * @param unit    时间单位, 天:TimeUnit.DAYS 小时:TimeUnit.HOURS 分钟:TimeUnit.MINUTES
      *                秒:TimeUnit.SECONDS 毫秒:TimeUnit.MILLISECONDS
      */
-    public void setEx(String key, String value, long timeout, TimeUnit unit) {
-        redisTemplate.opsForValue().set(key, value, timeout, unit);
+    public <T> void setEx(String key, T t, long timeout, TimeUnit unit) {
+        redisTemplate.opsForValue().set(key, t, timeout, unit);
     }
 
     /**
      * 只有在 key 不存在时设置 key 的值
      *
      * @param key
-     * @param value
+     * @param t
      * @return 之前已经存在返回false, 不存在返回true
      */
-    public boolean setIfAbsent(String key, String value) {
-        return redisTemplate.opsForValue().setIfAbsent(key, value);
+    public <T> boolean setIfAbsent(String key, T t) {
+        return redisTemplate.opsForValue().setIfAbsent(key, t);
     }
 
     /**