Răsfoiți Sursa

fix(修复金庸设备预警函数下因为Duration.ofHours导致redis报错问题): 修复金庸设备预警函数下因为Duration.ofHours导致redis报错问题

修复金庸设备预警函数下因为Duration.ofHours导致redis报错问题
zjian 1 lună în urmă
părinte
comite
49fdd562b9

+ 4 - 1
snowy-plugin/snowy-plugin-coldchain/src/main/java/vip/xiaonuo/coldchain/core/alarm/service/delay/DeviceAlertDelayService.java

@@ -6,6 +6,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.time.Duration;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author jackzhou 2025 11-03 23:05
@@ -28,7 +29,9 @@ public class DeviceAlertDelayService {
      */
     public void disableDeviceAlert(String deviceCode, long hours) {
         String key = buildDeviceKey(deviceCode);
-        redisTemplate.opsForValue().set(key, String.valueOf(hours), Duration.ofHours(hours));
+        redisTemplate.opsForValue().set(key, String.valueOf(hours), hours, TimeUnit.HOURS);
+        //下面方法会导致 ERR invalid expire time in setex
+//        redisTemplate.opsForValue().set(key, String.valueOf(hours), Duration.ofHours(hours));
     }
 
     /**