db_size
Retrieves the total number of keys in the current Redis database. Use to monitor database size and resource usage.
Instructions
获取当前数据库的键数量
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/redis_mcp_server/server.py:60-67 (handler)MCP tool handler for 'db_size'. Decorated with @mcp.tool(), it calls db.dbsize() and returns JSON-formatted result with the current database key count.
@mcp.tool() def db_size() -> str: """获取当前数据库的键数量""" try: result = db.dbsize() return json.dumps(result, ensure_ascii=False, indent=2) except Exception as e: return json.dumps({"error": str(e)}, ensure_ascii=False) - src/redis_mcp_server/db.py:94-96 (helper)The RedisConnection.dbsize() method that executes the actual Redis DBSIZE command and returns the database index and key count as a dict.
def dbsize(self) -> dict[str, Any]: """获取当前数据库键数量""" return {"db": self.config.db, "key_count": self._client.dbsize()} - src/redis_mcp_server/server.py:36-37 (registration)Tool registration via the @mcp.tool() decorator on the db_size function (line 60). All tools in this file are registered using FastMCP's decorator pattern.
@mcp.tool() def ping() -> str: