Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

lpush

Add a value to the beginning of a Redis list and optionally set an expiration time for the list.

Instructions

Push a value onto the left of a Redis list and optionally set an expiration time.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
valueYes
expireNo

Implementation Reference

  • The handler function for the 'lpush' MCP tool. Decorated with @mcp.tool(), it pushes a value to the left side of a Redis list using r.lpush(), optionally sets an expiration, and returns a success or error message.
    @mcp.tool()
    async def lpush(name: str, value: FieldT, expire: Optional[int] = None) -> str:
        """Push a value onto the left of a Redis list and optionally set an expiration time."""
        try:
            r = RedisConnectionManager.get_connection()
            r.lpush(name, value)
            if expire:
                r.expire(name, expire)
            return f"Value '{value}' pushed to the left of list '{name}'."
        except RedisError as e:
            return f"Error pushing value to list '{name}': {str(e)}"
  • The registration mechanism for all tools, including 'lpush'. Imports all modules in src/tools package, triggering the @mcp.tool() decorators to register the tools with the FastMCP server.
    def load_tools():
        import src.tools as tools_pkg
    
        for _, module_name, _ in pkgutil.iter_modules(tools_pkg.__path__):
            importlib.import_module(f"src.tools.{module_name}")
    
    
    # Initialize FastMCP server
    mcp = FastMCP("Redis MCP Server", dependencies=["redis", "dotenv", "numpy", "aiohttp"])
    
    # Load tools
    load_tools()

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