From 33b51c40ddd9750a19b2c6a6618fb22386f87cd7 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 13 十一月 2020 18:12:21 +0800
Subject: [PATCH] 增加强制不查询编码信息配置

---
 src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java |  206 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 191 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
index 0427f8b..e0f7e41 100644
--- a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
@@ -1,19 +1,18 @@
 package com.genersoft.iot.vmp.utils.redis;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.redis.connection.RedisConnection;
+import org.springframework.data.redis.core.*;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 /**    
  * @Description:Redis宸ュ叿绫�
- * @author: songww
+ * @author: swwheihei
  * @date:   2020骞�5鏈�6鏃� 涓嬪崍8:27:29     
  */
 @Component
@@ -68,14 +67,20 @@
      * @SuppressWarnings("unchecked") 蹇界暐绫诲瀷杞崲璀﹀憡
      * @param key 閿紙涓�涓垨鑰呭涓級
      */
-    public void del(String... key) {
-        if (key != null && key.length > 0) {
-            if (key.length == 1) {
-                redisTemplate.delete(key[0]);
-            } else {
-//                浼犲叆涓�涓� Collection<String> 闆嗗悎
-                redisTemplate.delete(CollectionUtils.arrayToList(key));
+    public boolean del(String... key) {
+    	try {
+    		if (key != null && key.length > 0) {
+                if (key.length == 1) {
+                    redisTemplate.delete(key[0]);
+                } else {
+//                    浼犲叆涓�涓� Collection<String> 闆嗗悎
+                    redisTemplate.delete(CollectionUtils.arrayToList(key));
+                }
             }
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
         }
     }
 
@@ -383,6 +388,121 @@
             return 0;
         }
     }
+//    ============================== ZSet ==============================
+
+    /**
+     * 娣诲姞涓�涓厓绱�, zset涓巗et鏈�澶х殑鍖哄埆灏辨槸姣忎釜鍏冪礌閮芥湁涓�涓猻core锛屽洜姝ゆ湁涓帓搴忕殑杈呭姪鍔熻兘;  zadd
+     *
+     * @param key
+     * @param value
+     * @param score
+     */
+    public void zAdd(String key, String value, double score) {
+        redisTemplate.opsForZSet().add(key, value, score);
+    }
+
+    /**
+     * 鍒犻櫎鍏冪礌 zrem
+     *
+     * @param key
+     * @param value
+     */
+    public void zRemove(String key, String value) {
+        redisTemplate.opsForZSet().remove(key, value);
+    }
+
+    /**
+     * score鐨勫鍔爋r鍑忓皯 zincrby
+     *
+     * @param key
+     * @param value
+     * @param score
+     */
+    public Double zIncrScore(String key, String value, double score) {
+        return redisTemplate.opsForZSet().incrementScore(key, value, score);
+    }
+
+    /**
+     * 鏌ヨvalue瀵瑰簲鐨剆core   zscore
+     *
+     * @param key
+     * @param value
+     * @return
+     */
+    public Double zScore(String key, String value) {
+        return redisTemplate.opsForZSet().score(key, value);
+    }
+
+    /**
+     * 鍒ゆ柇value鍦▃set涓殑鎺掑悕  zrank
+     *
+     * @param key
+     * @param value
+     * @return
+     */
+    public Long zRank(String key, String value) {
+        return redisTemplate.opsForZSet().rank(key, value);
+    }
+
+    /**
+     * 杩斿洖闆嗗悎鐨勯暱搴�
+     *
+     * @param key
+     * @return
+     */
+    public Long zSize(String key) {
+        return redisTemplate.opsForZSet().zCard(key);
+    }
+
+    /**
+     * 鏌ヨ闆嗗悎涓寚瀹氶『搴忕殑鍊硷紝 0 -1 琛ㄧず鑾峰彇鍏ㄩ儴鐨勯泦鍚堝唴瀹�  zrange
+     *
+     * 杩斿洖鏈夊簭鐨勯泦鍚堬紝score灏忕殑鍦ㄥ墠闈�
+     *
+     * @param key
+     * @param start
+     * @param end
+     * @return
+     */
+    public Set<String> ZRange(String key, int start, int end) {
+        return redisTemplate.opsForZSet().range(key, start, end);
+    }
+    /**
+     * 鏌ヨ闆嗗悎涓寚瀹氶『搴忕殑鍊煎拰score锛�0, -1 琛ㄧず鑾峰彇鍏ㄩ儴鐨勯泦鍚堝唴瀹�
+     *
+     * @param key
+     * @param start
+     * @param end
+     * @return
+     */
+    public Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(String key, int start, int end) {
+        return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
+    }
+    /**
+     * 鏌ヨ闆嗗悎涓寚瀹氶『搴忕殑鍊�  zrevrange
+     *
+     * 杩斿洖鏈夊簭鐨勯泦鍚堜腑锛宻core澶х殑鍦ㄥ墠闈�
+     *
+     * @param key
+     * @param start
+     * @param end
+     * @return
+     */
+    public Set<String> zRevRange(String key, int start, int end) {
+        return redisTemplate.opsForZSet().reverseRange(key, start, end);
+    }
+    /**
+     * 鏍规嵁score鐨勫�硷紝鏉ヨ幏鍙栨弧瓒虫潯浠剁殑闆嗗悎  zrangebyscore
+     *
+     * @param key
+     * @param min
+     * @param max
+     * @return
+     */
+    public Set<String> zSortRange(String key, int min, int max) {
+        return redisTemplate.opsForZSet().rangeByScore(key, min, max);
+    }
+
 
 //    ============================== List ==============================
 
@@ -539,7 +659,7 @@
             return 0;
         }
     }
-    
+
     /**
      * 妯$硦鏌ヨ
      * @param key 閿�
@@ -547,11 +667,67 @@
      */
     public List<Object> keys(String key) {
         try {
-        	Set<String> set = redisTemplate.keys(key);
+            Set<String> set = redisTemplate.keys(key);
             return new ArrayList<>(set);
         } catch (Exception e) {
             e.printStackTrace();
             return null;
         }
     }
+
+
+    /**
+     * 妯$硦鏌ヨ
+     * @param query 鏌ヨ鍙傛暟
+     * @return
+     */
+//    public List<Object> scan(String query) {
+//        List<Object> result = new ArrayList<>();
+//        try {
+//            Cursor<Map.Entry<Object,Object>> cursor = redisTemplate.opsForHash().scan("field",
+//                    ScanOptions.scanOptions().match(query).count(1000).build());
+//            while (cursor.hasNext()) {
+//                Map.Entry<Object,Object> entry = cursor.next();
+//                result.add(entry.getKey());
+//                Object key = entry.getKey();
+//                Object valueSet = entry.getValue();
+//            }
+//            //鍏抽棴cursor
+//            cursor.close();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return result;
+//    }
+
+    /**
+     * 妯$硦鏌ヨ
+     * @param query 鏌ヨ鍙傛暟
+     * @return
+     */
+    public List<Object> scan(String query) {
+        Set<String> keys = (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
+            Set<String> keysTmp = new HashSet<>();
+            Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(query).count(1000).build());
+            while (cursor.hasNext()) {
+                keysTmp.add(new String(cursor.next()));
+            }
+            return keysTmp;
+        });
+//        Set<String> keys = (Set<String>) redisTemplate.execute(new RedisCallback<Set<String>>(){
+//
+//            @Override
+//            public Set<String> doInRedis(RedisConnection connection) throws DataAccessException {
+//                Set<String> keysTmp = new HashSet<>();
+//                Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(query).count(1000).build());
+//                while (cursor.hasNext()) {
+//                    keysTmp.add(new String(cursor.next()));
+//                }
+//            return keysTmp;
+//            }
+//        });
+
+        return new ArrayList<>(keys);
+    }
+
 }

--
Gitblit v1.8.0