Explorar el Código

redis value NaN

xushili hace 1 año
padre
commit
b961f6040e

+ 13 - 4
redisread/src/main/java/com/gyee/redisread/task/TaskRedisRead.java

@@ -75,7 +75,12 @@ public class TaskRedisRead implements Runnable {
                         if (!Objects.equals(ChangedSave.map.get(pointid), datetime)) {
                             ChangedSave.map.put(pointid, datetime);
                             ts = datetime.length()>10?Long.valueOf(datetime): Long.valueOf(datetime)* 1000;
-                            bl = Double.valueOf(value) == 1;
+                            try{
+                                bl = Double.parseDouble(value) == 1;
+                            }catch (Exception e){
+                                log.warn(value);
+                                continue;
+                            }
                             //j++;
                             sb.append(pointid).append(" VALUES (").append(ts).append(",").append(bl).append(") ");
                         }
@@ -102,7 +107,6 @@ public class TaskRedisRead implements Runnable {
                     }
 
                     value = response.get(1);
-                    if (value == null || "".equals(value) || value.contains("-nan")) continue;
                     datetime = response.get(2);
                     if (StringUtils.isEmpty(datetime)) continue;
                     pointid = response.get(0);
@@ -112,8 +116,13 @@ public class TaskRedisRead implements Runnable {
                         if (!Objects.equals(ChangedSave.map.get(pointid), datetime)) {
                             ChangedSave.map.put(pointid, datetime);
                             ts = datetime.length()>10?Long.valueOf(datetime): Long.valueOf(datetime)* 1000;
-                            val = Double.valueOf(value);
-
+                            try{
+                                val = Double.parseDouble(value);
+                                if (Double.isNaN(val) || Double.isInfinite(val)) continue;
+                            }catch (Exception e){
+                                log.warn(value);
+                                continue;
+                            }
                             //j++;
                             sb.append(pointid).append(" VALUES (").append(ts).append(",").append(val).append(") ");
                         }