Skip to content

Expose MEMORY STATS to the python client #118

Open
@ctandon11

Description

@ctandon11

Description

Give the python client access to the Redis command MEMORY STATS by exposing it
through the Pybindings.

Justification

Users will be able to access information about the memory usage of the
server through the python client.

Implementation Strategy

MEMORY STATS will be an AddressAtCommand.

Note: This function returns a nested list of memory usage metrics and their values. Like ClusterInfoCommand, we should implement a MemoryStatsCommand subclass of AddressAtCommand that contains a separate parsing function, i.e. std::vector<std::pair<std::string, std::string>> MemoryStatsCommand::parse(CommandReply reply).

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

std::vector<std::pair<std::string, std::string>> Client::memory_stats(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.");
    }
    MemoryStatsCommand cmd;
    cmd.set_exec_address_port(host, port);

    cmd.add_field("MEMORY");
    cmd.add_field("STATS");

    CommandReply reply = _run(cmd);
    if (reply.has_error() > 0)
        throw std::runtime_error("MEMORY STATS 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