Skip to main content
Glama

key_delete_pattern

Delete multiple Redis keys matching a specified pattern using wildcards (*, ?, []) for efficient batch cleanup operations.

Instructions

批量删除匹配的键

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYes匹配模式(支持通配符 * ? [])

Implementation Reference

  • 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) } ] }; }
  • 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); }); }
  • 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'] }
  • Registration in the tool dispatch switch statement that routes calls to the handler.
    case 'key_delete_pattern': return await this.handleKeyDeletePattern(args);
  • 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'] } },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pickstar-2002/redis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server