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
| Name | Required | Description | Default |
|---|---|---|---|
| expire_seconds | Yes | ||
| name | Yes |
Implementation Reference
- src/tools/misc.py:50-71 (handler)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)}"