Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

hset

Set a field in a Redis hash with an optional expiration time to manage structured data storage.

Instructions

Set a field in a hash stored at key with an optional expiration time.

Args: name: The Redis hash key. key: The field name inside the hash. value: The value to set. expire_seconds: Optional; time in seconds after which the key should expire.

Returns: A success message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
keyYes
valueYes
expire_secondsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'hset' tool. It is decorated with @mcp.tool() for registration and implements the logic to set a field in a Redis hash using hset, with optional expiration via expire.
    @mcp.tool()
    async def hset(
        name: str, key: str, value: str | int | float, expire_seconds: Optional[int] = None
    ) -> str:
        """Set a field in a hash stored at key with an optional expiration time.
    
        Args:
            name: The Redis hash key.
            key: The field name inside the hash.
            value: The value to set.
            expire_seconds: Optional; time in seconds after which the key should expire.
    
        Returns:
            A success message or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
            r.hset(name, key, str(value))
    
            if expire_seconds is not None:
                r.expire(name, expire_seconds)
    
            return f"Field '{key}' set successfully in hash '{name}'." + (
                f" Expires in {expire_seconds} seconds." if expire_seconds else ""
            )
        except RedisError as e:
            return f"Error setting field '{key}' in hash '{name}': {str(e)}"
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the action ('Set') and optional expiration, but does not disclose critical behavioral traits such as whether this overwrites existing fields, requires specific permissions, has rate limits, or what constitutes a 'success message' versus an 'error message'. For a mutation tool with zero annotation coverage, this is a significant gap.

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 appropriately sized and front-loaded: the first sentence states the core purpose, followed by a structured 'Args' and 'Returns' section. Every sentence earns its place by providing essential information without redundancy or fluff, making it efficient and easy to parse.

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?

Given the tool's moderate complexity (4 parameters, mutation operation) and the presence of an output schema (which handles return values), the description is largely complete. It covers purpose, parameters, and basic behavior, though it lacks details on error conditions or side effects. With no annotations, it could benefit from more behavioral context, but the output schema mitigates some gaps.

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

Parameters5/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 fully. It explicitly defines all four parameters ('name', 'key', 'value', 'expire_seconds') with clear semantics beyond the schema's basic types, explaining their roles in the Redis hash context (e.g., 'field name inside the hash', 'time in seconds after which the key should expire'). This adds substantial value over the bare schema.

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 a field in a hash stored at key') and resource ('Redis hash'), distinguishing it from siblings like 'set' (which sets a simple key-value pair) and 'hget' (which retrieves from a hash). It precisely defines the operation without being vague or tautological.

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

Usage Guidelines3/5

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

The description implies usage for setting hash fields with optional expiration, but does not explicitly state when to use this tool versus alternatives like 'set' (for simple keys) or 'json_set' (for JSON data). It provides basic context but lacks explicit guidance on exclusions or comparisons with sibling tools.

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