rename
Change the name of a Redis key from an old identifier to a new one, updating data references within the database.
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 |
|---|---|---|---|
| old_key | Yes | ||
| new_key | Yes |
Implementation Reference
- src/tools/misc.py:73-103 (handler)The core handler function for the 'rename' MCP tool. It uses RedisConnectionManager to get a connection, checks if the old_key exists, renames it to new_key using r.rename(), and returns success or error dict.@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)}
- src/tools/misc.py:73-73 (registration)The @mcp.tool() decorator registers the rename function as an MCP tool.@mcp.tool()
- src/tools/misc.py:74-86 (schema)Type hints and docstring defining input parameters (old_key: str, new_key: str) and output format (Dict[str, Any] with status or error).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": "..."} """