key_delete_pattern
Delete multiple Redis keys matching a specified pattern using wildcards (*, ?, []) for efficient batch cleanup operations.
Instructions
批量删除匹配的键
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | 匹配模式(支持通配符 * ? []) |
Implementation Reference
- src/services/mcpService.ts:1296-1308 (handler)MCP tool handler that ensures Redis connection, calls deleteByPattern on RedisService with the input pattern, and formats the result as MCP response.private async handleKeyDeletePattern(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.deleteByPattern(args.pattern); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/redisService.ts:535-546 (helper)Implements the core logic: retrieves keys matching the pattern using Redis KEYS command, then deletes them using DEL if any found.async deleteByPattern(pattern: string): Promise<RedisOperationResult<number>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); const keys = await this.client.keys(pattern); if (keys.length === 0) { return 0; } return await this.client.del(keys); }); }
- src/services/mcpService.ts:562-568 (schema)Input schema defining the 'pattern' parameter as a required string for matching keys with wildcards (* ? []).inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: '匹配模式(支持通配符 * ? [])' } }, required: ['pattern'] }
- src/services/mcpService.ts:698-699 (registration)Registration in the tool dispatch switch statement that routes calls to the handler.case 'key_delete_pattern': return await this.handleKeyDeletePattern(args);
- src/services/mcpService.ts:559-569 (registration)Tool registration in the MCP server's tools list, including name, description, and schema.{ name: 'key_delete_pattern', description: '批量删除匹配的键', inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: '匹配模式(支持通配符 * ? [])' } }, required: ['pattern'] } },