sadd
Add values to Redis sets with optional expiration times to manage collections and implement time-limited data structures.
Instructions
Add a value to a Redis set with an optional expiration time.
Args: name: The Redis set key. value: The value to add to the set. expire_seconds: Optional; time in seconds after which the set should expire.
Returns: A success message or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| value | Yes | ||
| expire_seconds | No |
Implementation Reference
- src/tools/set.py:9-32 (handler)The main handler function for the 'sadd' tool, decorated with @mcp.tool() which registers it as an MCP tool. It adds a member to a Redis set with optional expiration time.@mcp.tool() async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str: """Add a value to a Redis set with an optional expiration time. Args: name: The Redis set key. value: The value to add to the set. expire_seconds: Optional; time in seconds after which the set should expire. Returns: A success message or an error message. """ try: r = RedisConnectionManager.get_connection() r.sadd(name, value) if expire_seconds is not None: r.expire(name, expire_seconds) return f"Value '{value}' added successfully to set '{name}'." + ( f" Expires in {expire_seconds} seconds." if expire_seconds else "" ) except RedisError as e: return f"Error adding value '{value}' to set '{name}': {str(e)}"
- src/tools/set.py:9-10 (registration)The @mcp.tool() decorator registers the sadd function as the 'sadd' MCP tool.@mcp.tool() async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str:
- src/tools/set.py:10-20 (schema)The function signature and docstring define the input schema (name: str, value: str, expire_seconds: Optional[int]) and output (str).async def sadd(name: str, value: str, expire_seconds: Optional[int] = None) -> str: """Add a value to a Redis set with an optional expiration time. Args: name: The Redis set key. value: The value to add to the set. expire_seconds: Optional; time in seconds after which the set should expire. Returns: A success message or an error message. """