Info.fromResult constructor

Info.fromResult(
  1. List<String> result
)

Implementation

factory Info.fromResult(List<String> result) {
  Map<String, String> infoMap = {};

  for (String line in result) {
    // 忽略空行和以 # 开头的行(节名)
    if (line.isEmpty || line.startsWith('#')) {
      continue;
    }

    // 分割属性行到键值对
    int delimiterIndex = line.indexOf(':');
    if (delimiterIndex != -1) {
      String key = line.substring(0, delimiterIndex);
      String value = line.substring(delimiterIndex + 1);
      infoMap[key] = value;
    }
  }

  return Info(
    server: ServerInfo.fromMap(infoMap),
    clients: ClientsInfo.fromMap(infoMap),
    memory: MemoryInfo.fromMap(infoMap),
    persistence: PersistenceInfo.fromMap(infoMap),
    stats: StatsInfo.fromMap(infoMap),
    replication: ReplicationInfo.fromMap(infoMap),
    cpu: CPUInfo.fromMap(infoMap),
    cluster: ClusterInfo.fromMap(infoMap),
    keyspace: KeyspaceInfo.fromMap(infoMap),
  );
}