string_decr
Decrement numeric values stored in Redis keys by a specified amount. Use this tool to reduce counters, track decreasing metrics, or manage decrement operations in Redis databases.
Instructions
递减数值
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 键名 | |
| decrement | No | 减量值(可选,默认为 1) |
Implementation Reference
- src/services/mcpService.ts:138-148 (registration)Registration of the string_decr tool in the listTools response, including name, description, and input schema.{ name: 'string_decr', description: '递减数值', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' }, decrement: { type: 'number', description: '减量值(可选,默认为 1)' } }, required: ['key'] }
- src/services/mcpService.ts:871-883 (handler)The main MCP tool handler function for string_decr. Ensures Redis connection, calls RedisService.decr(key, decrement), and returns the result as formatted JSON text content.private async handleStringDecr(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.decr(args.key, args.decrement); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/redisService.ts:173-183 (helper)Core helper method in RedisService that performs the actual DECR/DECRBY operation using the Redis client.async decr(key: string, decrement: number = 1): Promise<RedisOperationResult<number>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); if (decrement === 1) { return await this.client.decr(key); } else { return await this.client.decrBy(key, decrement); } }); }