rename
Renames a Redis key from old_key to new_key, providing a dictionary indicating the operation's success or error. Use it to update key names efficiently in Redis databases.
Instructions
Renames a Redis key from old_key to new_key.
Args: old_key (str): The current name of the Redis key to rename. new_key (str): The new name to assign to the key.
Returns: Dict[str, Any]: A dictionary containing the result of the operation. On success: {"status": "success", "message": "..."} On error: {"error": "..."}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| new_key | Yes | ||
| old_key | Yes |
Implementation Reference
- src/tools/misc.py:73-103 (handler)The 'rename' tool handler function, including registration via @mcp.tool() decorator, input schema via type hints and docstring, and execution logic using RedisConnectionManager to rename a Redis key.@mcp.tool() async def rename(old_key: str, new_key: str) -> Dict[str, Any]: """ Renames a Redis key from old_key to new_key. Args: old_key (str): The current name of the Redis key to rename. new_key (str): The new name to assign to the key. Returns: Dict[str, Any]: A dictionary containing the result of the operation. On success: {"status": "success", "message": "..."} On error: {"error": "..."} """ try: r = RedisConnectionManager.get_connection() # Check if the old key exists if not r.exists(old_key): return {"error": f"Key '{old_key}' does not exist."} # Rename the key r.rename(old_key, new_key) return { "status": "success", "message": f"Renamed key '{old_key}' to '{new_key}'", } except RedisError as e: return {"error": str(e)}