Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

set

Store string values in Redis with optional expiration times to manage key-value data persistence and caching.

Instructions

Set a Redis string value with an optional expiration time.

Args: key (str): The key to set. value (str, bytes, int, float, dict): The value to store. expiration (int, optional): Expiration time in seconds.

Returns: str: Confirmation message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
valueYes
expirationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler for the 'set' tool: sets a Redis string key with optional expiration using Redis SET or SETEX.
    @mcp.tool()
    async def set(
        key: str,
        value: Union[str, bytes, int, float, dict],
        expiration: Optional[int] = None,
    ) -> str:
        """Set a Redis string value with an optional expiration time.
    
        Args:
            key (str): The key to set.
            value (str, bytes, int, float, dict): The value to store.
            expiration (int, optional): Expiration time in seconds.
    
        Returns:
            str: Confirmation message or an error message.
        """
        if isinstance(value, bytes):
            encoded_value = value
        elif isinstance(value, dict):
            encoded_value = json.dumps(value)
        else:
            encoded_value = str(value)
    
        if isinstance(encoded_value, str):
            encoded_value = encoded_value.encode("utf-8")
    
        try:
            r: Redis = RedisConnectionManager.get_connection()
            if expiration:
                r.setex(key, expiration, encoded_value)
            else:
                r.set(key, encoded_value)
    
            return f"Successfully set {key}" + (
                f" with expiration {expiration} seconds" if expiration else ""
            )
        except RedisError as e:
            return f"Error setting key {key}: {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 full burden. It mentions the action ('Set') and optional expiration, but lacks critical behavioral details: whether this overwrites existing keys, requires specific permissions, has rate limits, or what the confirmation/error messages contain. For a mutation tool with zero annotation coverage, this is insufficient.

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 appropriately sized and front-loaded with the core purpose in the first sentence. The Args/Returns sections are structured but slightly verbose; every sentence earns its place by adding parameter and return details, though it could be more streamlined.

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 a mutation tool with no annotations, 3 parameters, 0% schema coverage, and an output schema (for returns), the description is moderately complete. It covers purpose and parameters adequately but lacks behavioral context (e.g., overwrite behavior, error conditions) that would be needed for full agent understanding.

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 semantics: 'key' is for identification, 'value' specifies allowed data types (str, bytes, int, float, dict), and 'expiration' is optional with units (seconds). This clarifies beyond the schema's basic types, though it doesn't cover all edge cases (e.g., dict serialization).

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 Redis string value') and resource ('Redis string value'), distinguishing it from siblings like 'get' (retrieves), 'delete' (removes), or 'expire' (sets expiration only). It precisely identifies the tool's function beyond just the name.

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 storing data in Redis with optional expiration, but does not explicitly state when to use this versus alternatives like 'hset' (for hashes), 'json_set' (for JSON), or 'expire' (for modifying expiration only). No guidance on prerequisites or exclusions is provided.

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