key_expire
Set expiration time for Redis keys to automatically remove data after a specified duration, managing memory and data lifecycle.
Instructions
设置键过期时间
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 键名 | |
| seconds | Yes | 过期时间(秒) |
Implementation Reference
- src/services/mcpService.ts:1211-1223 (handler)The main handler function for the 'key_expire' MCP tool. It ensures Redis connection and calls RedisService.expire to set key expiration time.private async handleKeyExpire(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.expire(args.key, args.seconds); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:503-514 (schema)The input schema definition for the 'key_expire' tool, registered in the ListTools response.{ name: 'key_expire', description: '设置键过期时间', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' }, seconds: { type: 'number', description: '过期时间(秒)' } }, required: ['key', 'seconds'] } },
- src/services/mcpService.ts:688-689 (registration)The dispatch/registration case in the CallToolRequestHandler switch statement that routes 'key_expire' calls to the handler.case 'key_expire': return await this.handleKeyExpire(args);
- src/services/redisService.ts:474-480 (helper)Supporting utility method in RedisService that implements the actual Redis EXPIRE command via the redis client.async expire(key: string, seconds: number): Promise<RedisOperationResult<boolean>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); const result = await this.client.expire(key, seconds); return Boolean(result); }); }