houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.convert.redis;
H 2
3 import cn.hutool.core.util.StrUtil;
4 import com.iailab.module.infra.controller.admin.redis.vo.RedisMonitorRespVO;
5 import org.mapstruct.Mapper;
6 import org.mapstruct.factory.Mappers;
7
8 import java.util.ArrayList;
9 import java.util.Properties;
10
11 @Mapper
12 public interface RedisConvert {
13
14     RedisConvert INSTANCE = Mappers.getMapper(RedisConvert.class);
15
16     default RedisMonitorRespVO build(Properties info, Long dbSize, Properties commandStats) {
17         RedisMonitorRespVO respVO = RedisMonitorRespVO.builder().info(info).dbSize(dbSize)
18                 .commandStats(new ArrayList<>(commandStats.size())).build();
19         commandStats.forEach((key, value) -> {
20             respVO.getCommandStats().add(RedisMonitorRespVO.CommandStat.builder()
21                     .command(StrUtil.subAfter((String) key, "cmdstat_", false))
22                     .calls(Long.valueOf(StrUtil.subBetween((String) value, "calls=", ",")))
23                     .usec(Long.valueOf(StrUtil.subBetween((String) value, "usec=", ",")))
24                     .build());
25         });
26         return respVO;
27     }
28
29 }