dbsize
Retrieve the total number of keys stored in a Redis database using this tool, enabling efficient data management and monitoring for Redis MCP Server users.
Instructions
Get the number of keys stored in the Redis database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/server_management.py:7-14 (handler)The dbsize MCP tool handler function, decorated with @mcp.tool(), which gets the number of keys in the current Redis database by calling r.dbsize()@mcp.tool() async def dbsize() -> int: """Get the number of keys stored in the Redis database""" try: r = RedisConnectionManager.get_connection() return r.dbsize() except RedisError as e: return f"Error getting database size: {str(e)}"
- src/common/server.py:6-17 (registration)The load_tools() function and its invocation, which dynamically imports all src.tools modules (including server_management.py), thereby registering the dbsize tool via its @mcp.tool() decorator.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()