hget
Retrieve the value of a specific field within a Redis hash using key and field name, enabling efficient data access and management in Redis MCP Server.
Instructions
Get the value of a field in a Redis hash.
Args: name: The Redis hash key. key: The field name inside the hash.
Returns: The field value or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | ||
| name | Yes |
Implementation Reference
- src/tools/hash.py:39-55 (handler)The 'hget' tool handler function, decorated with @mcp.tool(). It connects to Redis via RedisConnectionManager, performs r.hget(name, key), and returns the value or an appropriate message on error or not found.@mcp.tool() async def hget(name: str, key: str) -> str: """Get the value of a field in a Redis hash. Args: name: The Redis hash key. key: The field name inside the hash. Returns: The field value or an error message. """ try: r = RedisConnectionManager.get_connection() value = r.hget(name, key) return value if value else f"Field '{key}' not found in hash '{name}'." except RedisError as e: return f"Error getting field '{key}' from hash '{name}': {str(e)}"
- src/common/server.py:6-17 (registration)Registers all MCP tools by dynamically importing every module in src/tools (including hash.py containing hget), which executes the @mcp.tool() decorators.def load_tools(): import src.tools as tools_pkg for _, module_name, _ in pkgutil.iter_modules(tools_pkg.__path__): importlib.import_module(f"src.tools.{module_name}") # Initialize FastMCP server mcp = FastMCP("Redis MCP Server", dependencies=["redis", "dotenv", "numpy", "aiohttp"]) # Load tools load_tools()