Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

zadd

Add members with scores to a Redis sorted set and optionally set expiration times for time-sensitive data management.

Instructions

Add a member to a Redis sorted set with an optional expiration time.

Args: key (str): The sorted set key. score (float): The score of the member. member (str): The member to add. expiration (int, optional): Expiration time in seconds.

Returns: str: Confirmation message or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes
scoreYes
memberYes
expirationNo

Implementation Reference

  • The main handler function for the 'zadd' tool. It is decorated with @mcp.tool(), which registers it as an MCP tool. The function adds a member with a score to a Redis sorted set and optionally sets an expiration on the key.
    @mcp.tool() async def zadd( key: str, score: float, member: str, expiration: Optional[int] = None ) -> str: """Add a member to a Redis sorted set with an optional expiration time. Args: key (str): The sorted set key. score (float): The score of the member. member (str): The member to add. expiration (int, optional): Expiration time in seconds. Returns: str: Confirmation message or an error message. """ try: r = RedisConnectionManager.get_connection() r.zadd(key, {member: score}) if expiration: r.expire(key, expiration) return f"Successfully added {member} to {key} with score {score}" + ( f" and expiration {expiration} seconds" if expiration else "" ) except RedisError as e: return f"Error adding to sorted set {key}: {str(e)}"
  • Input schema defined by function parameters with type hints and comprehensive docstring describing args and return type.
    async def zadd( key: str, score: float, member: str, expiration: Optional[int] = None ) -> str:

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