Skip to main content
Glama
lm203688

redis-mcp-server

by lm203688

set_expire

Set an expiration time in seconds on a Redis key. The key will be automatically deleted after the specified duration.

Instructions

设置键的过期时间(需要关闭只读模式)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesRedis键名
secondsYes过期时间(秒)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler logic for set_expire. Checks write permission, verifies key access, then calls Redis EXPIRE command. Returns success status along with the key and expire seconds.
    def set_expire(self, key: str, seconds: int) -> dict[str, Any]:
        """设置键的过期时间"""
        self._check_write_permission()
        if not self._is_key_allowed(key):
            raise PermissionError(f"键 '{key}' 不允许访问")
        result = self._client.expire(key, seconds)
        return {"key": key, "expire_seconds": seconds, "success": result}
  • MCP tool wrapper for set_expire. Registered with @mcp.tool() decorator, calls db.set_expire(), serializes result to JSON, handles PermissionError and other exceptions.
    @mcp.tool()
    def set_expire(key: str, seconds: int) -> str:
        """设置键的过期时间(需要关闭只读模式)
    
        Args:
            key: Redis键名
            seconds: 过期时间(秒)
        """
        try:
            result = db.set_expire(key, seconds)
            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)
  • Test that verifies set_expire is registered as a tool in the MCP server's tool manager.
    def test_server_has_tools(self):
        tool_names = list(self.server.mcp._tool_manager._tools.keys())
        expected = [
            "ping", "server_info", "db_size", "scan_keys",
            "get_key_type", "get_key_value", "get_hash",
            "get_memory_usage", "set_string", "delete_keys", "set_expire",
        ]
Behavior3/5

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

With no annotations, the description indicates this is a write operation requiring read-only mode to be closed, but does not disclose behavior when read-only mode is on or other side effects like overwriting existing TTL.

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

Conciseness5/5

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

The description is a single, focused sentence that conveys the core purpose and a key constraint, with no wasted words.

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

Completeness4/5

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

For a simple mutation tool with two well-documented parameters and an implied output schema, the description provides essential context (prerequisite) and purpose, though it could mention behavior like overwriting existing expiration.

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?

The input schema has 100% coverage with descriptions for both parameters (key name and seconds). The tool description adds minimal meaning beyond the schema, so a baseline score of 3 is appropriate.

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 sets a key's expiration time using the verb 'set' and the resource 'expiration time of key'. It distinguishes itself from siblings like set_string, get_key_value, and delete_keys, which have different purposes.

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

Usage Guidelines4/5

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

The description mentions a prerequisite (read-only mode must be off), which guides usage context, but does not explicitly state when to use this tool versus alternatives like delete_keys or set_string for other operations.

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