From b260ef7ab6ea46e07f91b96d289a90122735cd75 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期四, 06 五月 2021 11:54:23 +0800
Subject: [PATCH] 更新mysql驱动名
---
src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java | 89 +++++++++++++++++++++++++++++++++++---------
1 files changed, 71 insertions(+), 18 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 463d942..5db3c7f 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,14 +1,10 @@
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.data.redis.core.ZSetOperations;
+import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@@ -18,6 +14,7 @@
* @date: 2020骞�5鏈�6鏃� 涓嬪崍8:27:29
*/
@Component
+@SuppressWarnings(value = {"rawtypes", "unchecked"})
public class RedisUtil {
@Autowired
@@ -399,7 +396,7 @@
* @param value
* @param score
*/
- public void zAdd(String key, String value, double score) {
+ public void zAdd(Object key, Object value, double score) {
redisTemplate.opsForZSet().add(key, value, score);
}
@@ -409,7 +406,7 @@
* @param key
* @param value
*/
- public void zRemove(String key, String value) {
+ public void zRemove(Object key, Object value) {
redisTemplate.opsForZSet().remove(key, value);
}
@@ -420,7 +417,7 @@
* @param value
* @param score
*/
- public Double zIncrScore(String key, String value, double score) {
+ public Double zIncrScore(Object key, Object value, double score) {
return redisTemplate.opsForZSet().incrementScore(key, value, score);
}
@@ -431,7 +428,7 @@
* @param value
* @return
*/
- public Double zScore(String key, String value) {
+ public Double zScore(Object key, Object value) {
return redisTemplate.opsForZSet().score(key, value);
}
@@ -442,7 +439,7 @@
* @param value
* @return
*/
- public Long zRank(String key, String value) {
+ public Long zRank(Object key, Object value) {
return redisTemplate.opsForZSet().rank(key, value);
}
@@ -452,7 +449,7 @@
* @param key
* @return
*/
- public Long zSize(String key) {
+ public Long zSize(Object key) {
return redisTemplate.opsForZSet().zCard(key);
}
@@ -466,7 +463,7 @@
* @param end
* @return
*/
- public Set<String> ZRange(String key, int start, int end) {
+ public Set<Object> ZRange(Object key, int start, int end) {
return redisTemplate.opsForZSet().range(key, start, end);
}
/**
@@ -477,7 +474,7 @@
* @param end
* @return
*/
- public Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(String key, int start, int end) {
+ public Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(Object key, int start, int end) {
return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
}
/**
@@ -490,7 +487,7 @@
* @param end
* @return
*/
- public Set<String> zRevRange(String key, int start, int end) {
+ public Set<String> zRevRange(Object key, int start, int end) {
return redisTemplate.opsForZSet().reverseRange(key, start, end);
}
/**
@@ -501,7 +498,7 @@
* @param max
* @return
*/
- public Set<String> zSortRange(String key, int min, int max) {
+ public Set<String> zSortRange(Object key, int min, int max) {
return redisTemplate.opsForZSet().rangeByScore(key, min, max);
}
@@ -661,7 +658,7 @@
return 0;
}
}
-
+
/**
* 妯$硦鏌ヨ
* @param key 閿�
@@ -669,11 +666,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