sadd
Add a value to a Redis set with an optional expiration time. Specify the set key, value, and duration in seconds for automatic expiration.
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 |
|---|---|---|---|
| expire_seconds | No | ||
| name | Yes | ||
| value | Yes |
Implementation Reference
- src/tools/set.py:9-32 (handler)The 'sadd' tool handler: adds a value to a Redis set key with optional expiration time. Registered via the @mcp.tool() decorator. Uses RedisConnectionManager for Redis operations and handles RedisError exceptions.@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/common/server.py:6-17 (registration)The load_tools() function imports all modules in src/tools/, which triggers the @mcp.tool() decorators to register all tools, including 'sadd' from set.py.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()