Skip to content

Expose LATENCY LATEST to the python client #126

Open
@ctandon11

Description

@ctandon11

Description

Give the python client access to the Redis command LATENCY LATEST by exposing it
through the Pybindings.

Justification

The user will be able to access the latest latency events logged.

Implementation Strategy

LATENCY LATEST will be an AddressAtCommand.

Note: This function returns an array where each element is a four elements array representing the event's name, timestamp, latest and all-time latency measurements. Like ClusterInfoCommand, we should implement a LatencyLatestCommand subclass of AddressAtCommand that contains a separate parsing function, i.e. std::vector<std::vector<std::string>> LatencyLatestCommand::parse(CommandReply reply).

The implementation will look something like this in client.cpp:

std::vector<std::vector<std::string>> Client::latency_latest(std::string address)
{
    std::string host = address.substr(0, address.find(":"));
    uint64_t port = std::stoul(address.substr(address.find(":") + 1),
                                nullptr, 0);
    if (host.empty() or port == 0){
        throw std::runtime_error(std::string(address) +
                                 "is not a valid database node address.");
    }
    LatencyLatestCommand cmd;
    cmd.set_exec_address_port(host, port);

    cmd.add_field("LATENCY");
    cmd.add_field("LATEST");

    CommandReply reply = _run(cmd);
    if (reply.has_error() > 0)
        throw std::runtime_error("LATENCY RESET command failed");


    return cmd.parse(reply);
}

This functionality then needs to be exposed through the Pybindings and pyclient.cpp file to the python client layer. For unit testing, make sure an invalid address throws an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: pythonIssues related to the Python Clienttype: featureIssues that include feature request or feature idea

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions