Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

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
NameRequiredDescriptionDefault
expire_secondsNo
nameYes
valueYes

Implementation Reference

  • 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)}"
  • 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()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/redis/mcp-redis'

If you have feedback or need assistance with the MCP directory API, please join our Discord server