hset
Set or update a field in a Redis hash with an optional expiration time. Specify the hash key, field name, value, and optional expiry in seconds for efficient data management.
Instructions
Set a field in a hash stored at key with an optional expiration time.
Args: name: The Redis hash key. key: The field name inside the hash. value: The value to set. expire_seconds: Optional; 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 | No | ||
| key | Yes | ||
| name | Yes | ||
| value | Yes |
Implementation Reference
- src/tools/hash.py:10-37 (handler)The main handler function for the 'hset' MCP tool. It sets a field in a Redis hash with optional expiration, decorated with @mcp.tool() for automatic registration.@mcp.tool() async def hset( name: str, key: str, value: str | int | float, expire_seconds: Optional[int] = None ) -> str: """Set a field in a hash stored at key with an optional expiration time. Args: name: The Redis hash key. key: The field name inside the hash. value: The value to set. expire_seconds: Optional; time in seconds after which the key should expire. Returns: A success message or an error message. """ try: r = RedisConnectionManager.get_connection() r.hset(name, key, str(value)) if expire_seconds is not None: r.expire(name, expire_seconds) return f"Field '{key}' set successfully in hash '{name}'." + ( f" Expires in {expire_seconds} seconds." if expire_seconds else "" ) except RedisError as e: return f"Error setting field '{key}' in hash '{name}': {str(e)}"
- src/tools/hash.py:10-10 (registration)The @mcp.tool() decorator registers the hset function as an MCP tool.@mcp.tool()