Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

expire

Set expiration time for Redis keys to automatically remove data after specified seconds, managing memory and data lifecycle.

Instructions

Set an expiration time for a Redis key.

Args: name: The Redis key. expire_seconds: Time in seconds after which the key should expire.

Returns: A success message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
expire_secondsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'expire' tool. It sets an expiration time on a specified Redis key using the Redis EXPIRE command. Includes input validation via type hints and docstring, error handling for Redis errors, and returns a success or error message.
    @mcp.tool()
    async def expire(name: str, expire_seconds: int) -> str:
        """Set an expiration time for a Redis key.
    
        Args:
            name: The Redis key.
            expire_seconds: Time in seconds after which the key should expire.
    
        Returns:
            A success message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            success = r.expire(name, expire_seconds)
            return (
                f"Expiration set to {expire_seconds} seconds for '{name}'."
                if success
                else f"Key '{name}' does not exist."
            )
        except RedisError as e:
            return f"Error setting expiration for key '{name}': {str(e)}"
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions the tool sets expiration and returns success/error messages, but doesn't disclose critical behaviors like whether it modifies existing expiration times, fails on non-existent keys, has rate limits, or requires specific permissions. This is inadequate for a mutation tool.

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?

The description is well-structured with a clear purpose statement followed by parameter and return sections. It's appropriately sized without fluff, though the 'Args' and 'Returns' labels are slightly redundant given the structured schema. Every sentence adds value.

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

Completeness3/5

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

Given the tool's moderate complexity (mutation with 2 params), no annotations, and an output schema (which covers return values), the description is partially complete. It explains the core action and parameters but lacks behavioral context (e.g., error conditions, idempotency) and usage guidelines, leaving gaps for an agent.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It adds meaningful context: 'name' is explained as 'The Redis key' (clarifying it's not a generic identifier), and 'expire_seconds' as 'Time in seconds after which the key should expire' (specifying units and purpose). This goes beyond the bare schema, though it could detail constraints like valid ranges.

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 specific action ('Set an expiration time') and target resource ('for a Redis key'), distinguishing it from siblings like 'delete' (permanent removal) or 'rename' (key modification). It precisely defines the tool's function without ambiguity.

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 is provided on when to use this tool versus alternatives. For example, it doesn't mention whether it works only on existing keys, how it differs from 'delete' (which permanently removes keys), or if there are prerequisites like key existence. The description lacks context for tool selection.

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/redis/mcp-redis'

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