Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

expire

Configure automatic Redis key expiration by specifying a key name and a time duration in seconds. Ensures efficient data management by removing stale entries.

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
expire_secondsYes
nameYes

Implementation Reference

  • The 'expire' tool handler: sets TTL on a Redis key using the Redis EXPPIRE command. Includes decorator for MCP registration, type hints for schema, and full implementation logic.
    @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)}"

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