From d8aaa53ac2181dec6e47ba18e9caa939876617d1 Mon Sep 17 00:00:00 2001 From: xce Date: Sun, 18 Jan 2026 16:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=8F=96=E6=B6=88=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=97=B6=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD=E9=94=81?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/MqttMessageHandler.java | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java b/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java index 3fc209e..97f43c6 100644 --- a/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java +++ b/agri-framework/src/main/java/com/agri/framework/interceptor/MqttMessageHandler.java @@ -23,9 +23,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.SmartLifecycle; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.stereotype.Component; @@ -740,48 +738,10 @@ public class MqttMessageHandler implements SmartLifecycle { log.error("【全量取消】Redis批量删除失败", e); throw new RuntimeException("全量取消订阅失败:" + e.getMessage()); } - - // 6. 清理该前端持有的分布式锁(精准扫描,提升效率) - Set lockKeys = scanRedisKeys("lock:*:" + clientId); - if (lockKeys != null && !lockKeys.isEmpty()) { - stringRedisTemplate.delete(lockKeys); // 批量删除锁,无需遍历 - log.info("【全量取消】清理前端{}持有的{}个分布式锁", clientId, lockKeys.size()); - } - log.info("【全量取消】前端{}成功取消{}个设备的订阅", clientId, deviceSet.size()); return frontendTopics; } - // 保留原有scanRedisKeys方法(兼容JDK 8) - private Set scanRedisKeys(String pattern) { - Set keys = new HashSet<>(); - try { - stringRedisTemplate.execute(new RedisCallback() { - @Override - public Void doInRedis(RedisConnection connection) throws DataAccessException { - RedisSerializer serializer = stringRedisTemplate.getStringSerializer(); - ScanOptions scanOptions = ScanOptions.scanOptions() - .match(pattern) - .count(100) - .build(); - Cursor cursor = connection.scan(scanOptions); - while (cursor.hasNext()) { - byte[] keyBytes = cursor.next(); - String key = serializer.deserialize(keyBytes); - if (key != null) { - keys.add(key); - } - } - cursor.close(); - return null; - } - }); - } catch (Exception e) { - log.error("Redis Scan查询失败,pattern={}", pattern, e); - } - return keys; - } - /** * 实际业务中:查询指定用户名下的所有设备ID(需替换为你的DAO/Service逻辑) * @return 设备ID列表