Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

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

Implementation Reference

  • 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:
  • 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. """

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