| 1321 | } |
| 1322 | |
| 1323 | std::string Server::GetRoleInfo() { |
| 1324 | if (IsSlave()) { |
| 1325 | std::vector<std::string> roles; |
| 1326 | roles.emplace_back("slave"); |
| 1327 | roles.emplace_back(master_host_); |
| 1328 | roles.emplace_back(std::to_string(master_port_)); |
| 1329 | |
| 1330 | auto state = GetReplicationState(); |
| 1331 | if (state == kReplConnected) { |
| 1332 | roles.emplace_back("connected"); |
| 1333 | } else if (state == kReplFetchMeta || state == kReplFetchSST) { |
| 1334 | roles.emplace_back("sync"); |
| 1335 | } else { |
| 1336 | roles.emplace_back("connecting"); |
| 1337 | } |
| 1338 | roles.emplace_back(std::to_string(storage->LatestSeqNumber())); |
| 1339 | return redis::ArrayOfBulkStrings(roles); |
| 1340 | } else { |
| 1341 | std::vector<std::string> list; |
| 1342 | |
| 1343 | { |
| 1344 | std::shared_lock<std::shared_mutex> guard(slave_threads_mu_); |
| 1345 | for (const auto &slave : slave_threads_) { |
| 1346 | if (slave->IsStopped()) continue; |
| 1347 | |
| 1348 | list.emplace_back(redis::ArrayOfBulkStrings({ |
| 1349 | slave->GetConn()->GetAnnounceIP(), |
| 1350 | std::to_string(slave->GetConn()->GetListeningPort()), |
| 1351 | std::to_string(slave->GetAckSeq()), |
| 1352 | })); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | auto multi_len = 2; |
| 1357 | if (list.size() > 0) { |
| 1358 | multi_len = 3; |
| 1359 | } |
| 1360 | std::string info; |
| 1361 | info.append(redis::MultiLen(multi_len)); |
| 1362 | info.append(redis::BulkString("master")); |
| 1363 | info.append(redis::BulkString(std::to_string(storage->LatestSeqNumber()))); |
| 1364 | if (list.size() > 0) { |
| 1365 | info.append(redis::Array(list)); |
| 1366 | } |
| 1367 | return info; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | std::string Server::GetLastRandomKeyCursor() { |
| 1372 | std::string cursor; |
no test coverage detected