key_delete_pattern
Remove multiple Redis keys matching a specified pattern using wildcard support. Simplify Redis data management by efficiently deleting bulk keys based on search criteria.
Instructions
批量删除匹配的键
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | 匹配模式(支持通配符 * ? []) |
Implementation Reference
- src/services/mcpService.ts:1296-1308 (handler)MCP tool handler function that ensures Redis connection and delegates to redisService.deleteByPattern to perform the deletion.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/mcpService.ts:559-569 (schema)Tool schema definition including input schema for pattern parameter.{ name: 'key_delete_pattern', description: '批量删除匹配的键', inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: '匹配模式(支持通配符 * ? [])' } }, required: ['pattern'] } },
- src/services/mcpService.ts:698-699 (registration)Registration in the tool dispatch switch statement.case 'key_delete_pattern': return await this.handleKeyDeletePattern(args);
- src/services/redisService.ts:535-546 (helper)Helper function implementing the core logic: scans for keys matching the pattern using KEYS and deletes them using DEL.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); }); }