int handleAllInstances()

in sonic-db-cli/sonic-db-cli.cpp [89:130]


int handleAllInstances(
    const string& netns,
    const string& operation,
    bool useUnixSocket)
{
    auto db_names = SonicDBConfig::getDbList(netns);
    // Operate All Redis Instances in Parallel
    // TODO: if one of the operations failed, it could fail quickly and not necessary to wait all other operations
    list<future<string>> responses;
    for (auto& db_name : db_names)
    {
        future<string> response = std::async(std::launch::async, handleSingleOperation, netns, db_name, operation, useUnixSocket);
        responses.push_back(std::move(response));
    }

    bool operation_failed = false;
    for (auto& response : responses)
    {
        auto respstr = response.get();
        if (respstr != "")
        {
            cout << respstr << endl;
            operation_failed = true;
        }
    }

    if (operation_failed)
    {
        return 1;
    }
    
    if (operation == "PING")
    {
        cout << "PONG" << endl;
    }
    else
    {
        cout << "OK" << endl;
    }

    return 0;
}