Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

lrange

Retrieve elements from a Redis list within a specified range. Input the list name, start, and stop indices to return a JSON string of the elements or an error message.

Instructions

Get elements from a Redis list within a specific range.

Returns: str: A JSON string containing the list of elements or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
startYes
stopYes

Implementation Reference

  • The handler function for the 'lrange' MCP tool. It uses RedisConnectionManager to get a connection, calls r.lrange(name, start, stop), converts the result to JSON if successful, or returns an error message. The @mcp.tool() decorator registers the tool and defines the input schema from the function signature (name: str, start: int, stop: int) and output as Union[str, List[str]] which is typically serialized.
    @mcp.tool() async def lrange(name: str, start: int, stop: int) -> Union[str, List[str]]: """Get elements from a Redis list within a specific range. Returns: str: A JSON string containing the list of elements or an error message. """ try: r = RedisConnectionManager.get_connection() values = r.lrange(name, start, stop) if not values: return f"List '{name}' is empty or does not exist." else: return json.dumps(values) except RedisError as e: return f"Error retrieving values from list '{name}': {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