Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

zadd

Add members to a Redis sorted set with assigned scores and optional expiration times. Enables efficient storage, retrieval, and management of ordered data structures in Redis.

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
expirationNo
keyYes
memberYes
scoreYes

Implementation Reference

  • The zadd tool handler function, decorated with @mcp.tool() for automatic registration. It adds a member to a Redis sorted set with score and optional expiration, using RedisConnectionManager.
    @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 optional expiration. Output is str confirmation or error.
    async def zadd( key: str, score: float, member: str, expiration: Optional[int] = None ) -> str:
  • Registration of the zadd tool via @mcp.tool() decorator.
    @mcp.tool()

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