| | |
| | | ObjectMapper mapper = new ObjectMapper(); // 创建 ObjectMapper 实例 |
| | | |
| | | // 空值检查,避免存储 null 值到 Redis |
| | | if (resultMap.get("bids") != null) { |
| | | if (resultMap.get("bids") != null && resultMap.get("asks") != null) { |
| | | Object bidsObj = resultMap.get("bids"); |
| | | Object asksObj = resultMap.get("asks"); |
| | | |
| | | if(bidsObj instanceof List && !((List<?>) bidsObj).isEmpty() && asksObj instanceof List && !((List<?>) asksObj).isEmpty()){ |
| | | if (bidsObj instanceof List && !((List<?>) bidsObj).isEmpty()) { |
| | | List<String> bidsList = (List<String>) bidsObj; |
| | | HashMap<String, Object> pvMap = new HashMap<>(); // 创建新的 HashMap 保存 bids 和 asks |
| | | pvMap.put("p", bidsList.get(0)); |
| | | pvMap.put("V", bidsList.get(1)); |
| | | pvMap.put("p", new BigDecimal(String.valueOf(bidsList.get(0))).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(String.valueOf(bidsList.get(1))).toPlainString()); |
| | | hashMap.put("bids",pvMap); |
| | | } |
| | | } |
| | | if (resultMap.get("asks") != null) { |
| | | |
| | | Object asksObj = resultMap.get("asks"); |
| | | if (asksObj instanceof List && !((List<?>) asksObj).isEmpty()) { |
| | | List<String> asksList = (List<String>) asksObj; |
| | | HashMap<String, Object> pvMap = new HashMap<>(); // 创建新的 HashMap 保存 bids 和 asks |
| | | pvMap.put("p", asksList.get(0)); |
| | | pvMap.put("V", asksList.get(1)); |
| | | pvMap.put("p", new BigDecimal(String.valueOf(asksList.get(0))).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(String.valueOf(asksList.get(1))).toPlainString()); |
| | | hashMap.put("asks",pvMap); |
| | | } |
| | | } |
| | | |
| | | String symbol = extractSymbolFromTopic(topic); // 从 topic 提取符号 |
| | | String key = PREFIX + symbol; // 创建 Redis 缓存键 |
| | | try { |
| | |
| | | } catch (JsonProcessingException e) { |
| | | log.error("将数据存入 Redis 时出错: {}", e.getMessage()); // 输出数据存储错误日志 |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | log.error("topic--->存入redis失败"); // 输出处理失败日志 |
| | | } |