string_decr
Decrease the value of a Redis string by a specified integer, defaulting to 1 if no value is provided. Ideal for decrementing counters or managing numeric data.
Instructions
递减数值
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| decrement | No | 减量值(可选,默认为 1) | |
| key | Yes | 键名 |
Implementation Reference
- src/services/mcpService.ts:871-883 (handler)MCP tool handler for 'string_decr': ensures Redis connection, calls RedisService.decr(), and returns formatted JSON response.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/mcpService.ts:138-148 (schema)Tool registration including name, description, and input schema definition for 'string_decr'.{ name: 'string_decr', description: '递减数值', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' }, decrement: { type: 'number', description: '减量值(可选,默认为 1)' } }, required: ['key'] }
- src/services/mcpService.ts:638-639 (registration)Dispatch case in the CallToolRequestSchema handler that routes 'string_decr' calls to the handler method.case 'string_decr': return await this.handleStringDecr(args);
- src/services/redisService.ts:173-183 (helper)Core Redis decrement implementation using client.decr() or decrBy() wrapped in error handling and connection management.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); } }); }