From 2bdced8b9cf552852fa7a881ef3b98273b989fe9 Mon Sep 17 00:00:00 2001 From: lin <648540858@qq.com> Date: Tue, 27 Jan 2026 14:21:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E5=BF=83=E8=B7=B3=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E5=92=8C=E6=B3=A8=E5=86=8C=E5=8E=86=E5=8F=B2=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../storager/impl/RedisCatchStorageImpl.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index 8e278dd8c..29c730428 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -561,9 +561,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { public Boolean execute(@NonNull RedisOperations operations) { // 1. 批量添加心跳数据到列表尾部 for (Device device : deviceList) { - operations.opsForList().rightPush(VideoManagerConstants.DEVICE_KEEPALIVE_PREFIX + device.getDeviceId(), device.getKeepaliveTimeStamp()); + Duration duration = Duration.ofHours(1); + String key = VideoManagerConstants.DEVICE_KEEPALIVE_PREFIX + device.getDeviceId(); + operations.opsForList().rightPush(key, device.getKeepaliveTimeStamp()); // 2. 截取列表,只保留最新 100 条 - operations.opsForList().trim((VideoManagerConstants.DEVICE_KEEPALIVE_PREFIX + device.getDeviceId()), -100, -1); + operations.opsForList().trim(key, -100, -1); + + // 为整个列表 Key 设置过期时间(核心:覆盖式设置,每次更新心跳都重置过期时间) + operations.expire(key, duration); } return true; } @@ -597,9 +602,15 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { public Boolean execute(@NonNull RedisOperations operations) { // 1. 批量添加心跳数据到列表尾部 for (Device device : deviceList) { - operations.opsForList().rightPush(VideoManagerConstants.DEVICE_REGISTER_PREFIX + device.getDeviceId(), device.getRegisterTimeStamp()); + Duration duration = Duration.ofHours(3); + String key = VideoManagerConstants.DEVICE_REGISTER_PREFIX + device.getDeviceId(); + operations.opsForList().rightPush(key, device.getRegisterTimeStamp()); // 2. 截取列表,只保留最新 100 条 - operations.opsForList().trim((VideoManagerConstants.DEVICE_REGISTER_PREFIX + device.getDeviceId()), -100, -1); + operations.opsForList().trim(key, -100, -1); + + // 为整个列表 Key 设置过期时间(核心:覆盖式设置,每次更新心跳都重置过期时间) + operations.expire(key, duration); + } return true; }