Skip to main content
Glama
lm203688

redis-mcp-server

by lm203688

get_memory_usage

Retrieve the memory usage of a specific Redis key to monitor and optimize storage efficiency.

Instructions

获取键的内存使用量

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesRedis键名

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for get_memory_usage. Decorated with @mcp.tool(), receives a key string, delegates to db.get_memory_usage(), and returns JSON with memory usage info.
    @mcp.tool()
    def get_memory_usage(key: str) -> str:
        """获取键的内存使用量
    
        Args:
            key: Redis键名
        """
        try:
            result = db.get_memory_usage(key)
            return json.dumps(result, ensure_ascii=False, indent=2)
        except PermissionError as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
        except Exception as e:
            return json.dumps({"error": str(e)}, ensure_ascii=False)
  • Core implementation in RedisConnection class. Calls Redis MEMORY USAGE command via self._client.memory_usage(key), returns dict with key, memory_bytes, and memory_human.
    def get_memory_usage(self, key: str) -> dict[str, Any]:
        """获取键的内存使用量"""
        if not self._is_key_allowed(key):
            raise PermissionError(f"键 '{key}' 不允许访问")
        usage = self._client.memory_usage(key)
        return {
            "key": key,
            "memory_bytes": usage,
            "memory_human": f"{usage / 1024:.2f} KB" if usage and usage >= 1024 else f"{usage} B" if usage else "N/A",
        }
  • Tool registration via the @mcp.tool() decorator on the handler function in server.py.
    @mcp.tool()
    def get_memory_usage(key: str) -> str:
  • Input schema: takes a single required 'key' parameter of type str. Output: returns a JSON string.
    def get_memory_usage(key: str) -> str:
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose any behavioral traits such as whether it's read-only, impact on server, or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single short sentence, no redundancy. However, it is very minimal.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simplicity of the tool, the description lacks context about usage conditions and behavior for missing keys, even though an output schema exists.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the description does not add meaning beyond the schema. Baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '获取键的内存使用量' clearly states the tool retrieves memory usage for a key. It is specific and distinguishes from siblings like get_key_value or get_key_type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. No mention of conditions or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lm203688/redis-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server