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

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)}"

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