lpush
Add a value to the beginning of a Redis list, with optional time-to-live expiration.
Instructions
Push a value onto the left of a Redis list and optionally set an expiration time.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| value | Yes | ||
| expire | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/tools/list.py:11-21 (handler)The implementation of the 'lpush' MCP tool. Uses @mcp.tool() decorator to register as a tool. Gets a Redis connection, calls LPUSH to push a value to the left of a list, optionally sets an expiration, and returns a success/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)}" - src/tools/list.py:12-12 (schema)Input schema for the 'lpush' tool: takes 'name' (str, the list name), 'value' (any field type), optional 'expire' (int). Returns a string.
async def lpush(name: str, value: FieldT, expire: Optional[int] = None) -> str: - src/common/server.py:13-14 (registration)The FastMCP server instance. The 'lpush' function in src/tools/list.py is registered as a tool via the @mcp.tool() decorator.
# Initialize FastMCP server mcp = FastMCP( - src/common/server.py:6-19 (registration)The load_tools() function that dynamically imports all modules from src.tools, which triggers the @mcp.tool() decorators and registers the tools including 'lpush'.
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", "python-dotenv", "numpy", "aiohttp"] ) # Load tools load_tools()