key_ttl
Retrieve the remaining time-to-live (TTL) for a specific key in Redis, helping manage key expiration and optimize database performance.
Instructions
获取键过期时间
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 键名 |
Implementation Reference
- src/services/mcpService.ts:1228-1240 (handler)The main handler function for the 'key_ttl' tool. It ensures a Redis connection exists, calls the ttl method on the RedisService with the provided key, formats the result as JSON text content, and returns it in the MCP response format.private async handleKeyTtl(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.ttl(args.key); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:515-525 (registration)The tool registration object returned by ListToolsRequestSchema handler. Defines the tool name, description, and input schema (requiring a 'key' string).{ name: 'key_ttl', description: '获取键过期时间', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' } }, required: ['key'] } },
- src/services/mcpService.ts:690-691 (registration)The switch case in the CallToolRequestSchema request handler that dispatches 'key_ttl' tool calls to the specific handleKeyTtl method.case 'key_ttl': return await this.handleKeyTtl(args);