Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

zrange

Retrieve a specific range of members from a Redis sorted set by specifying start and end indices, optionally including scores for precise data handling.

Instructions

Retrieve a range of members from a Redis sorted set.

Args: key (str): The sorted set key. start (int): The starting index. end (int): The ending index. with_scores (bool, optional): Whether to include scores in the result.

Returns: str: The sorted set members in the given range or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endYes
keyYes
startYes
with_scoresNo

Implementation Reference

  • The main handler function for the 'zrange' MCP tool. It is decorated with @mcp.tool() for registration and implements the logic to retrieve a range of members from a Redis sorted set, including optional scores. The function signature provides the input schema via type hints and docstring.
    @mcp.tool() async def zrange(key: str, start: int, end: int, with_scores: bool = False) -> str: """Retrieve a range of members from a Redis sorted set. Args: key (str): The sorted set key. start (int): The starting index. end (int): The ending index. with_scores (bool, optional): Whether to include scores in the result. Returns: str: The sorted set members in the given range or an error message. """ try: r = RedisConnectionManager.get_connection() members = r.zrange(key, start, end, withscores=with_scores) return ( str(members) if members else f"Sorted set {key} is empty or does not exist" ) except RedisError as e: return f"Error retrieving sorted set {key}: {str(e)}"

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