From c009637e0979741475e78c01551e7dcdcf99ecbf Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: 星期五, 13 十一月 2020 09:28:51 +0800 Subject: [PATCH] 增加录像回放结束后对设备发出的MediaStatus的回应并关流 --- src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java | 70 +++++++++++++++++++++++++++++++---- 1 files changed, 62 insertions(+), 8 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..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,14 +1,12 @@ 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.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; @@ -661,7 +659,7 @@ return 0; } } - + /** * 妯$硦鏌ヨ * @param key 閿� @@ -669,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