key_info
Retrieve detailed information about Redis keys, including type, TTL, and memory usage, to monitor and manage database performance.
Instructions
获取键信息
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 键名 |
Implementation Reference
- src/services/mcpService.ts:548-558 (registration)Registration of the 'key_info' tool in MCP server's ListTools response, including name, description, and input schema requiring a 'key' string.{ name: 'key_info', description: '获取键信息', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' } }, required: ['key'] } },
- src/services/mcpService.ts:1279-1291 (handler)MCP-level handler for 'key_info' tool that ensures Redis connection, calls redisService.getKeyInfo, and formats the response as MCP content.private async handleKeyInfo(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.getKeyInfo(args.key); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/redisService.ts:515-530 (handler)Core handler implementation in RedisService that retrieves the key's type and TTL using Redis client commands and returns RedisKeyInfo.async getKeyInfo(key: string): Promise<RedisOperationResult<RedisKeyInfo>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); const [type, ttl] = await Promise.all([ this.client.type(key), this.client.ttl(key) ]); return { key, type, ttl }; }); }
- src/types/index.ts:43-48 (schema)TypeScript interface defining the output structure for key information: key name, type, TTL (time to live), and optional size.export interface RedisKeyInfo { key: string; type: string; ttl: number; size?: number; }