string_incr
Increment numeric values stored in Redis keys by a specified amount or by default of 1. Use this tool to update counters, scores, or any numerical data in your Redis database.
Instructions
递增数值
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 键名 | |
| increment | No | 增量值(可选,默认为 1) |
Implementation Reference
- src/services/mcpService.ts:854-866 (handler)The main handler function for the 'string_incr' MCP tool. Ensures Redis connection and delegates to RedisService.incr method.private async handleStringIncr(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.incr(args.key, args.increment); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:126-137 (schema)Input schema definition and tool registration entry for 'string_incr' in the ListTools handler.{ name: 'string_incr', description: '递增数值', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' }, increment: { type: 'number', description: '增量值(可选,默认为 1)' } }, required: ['key'] } },
- src/services/mcpService.ts:636-637 (registration)Dispatch registration in the CallToolRequestSchema handler switch statement.case 'string_incr': return await this.handleStringIncr(args);
- src/services/redisService.ts:158-168 (helper)Supporting method in RedisService that implements the core Redis increment logic using client.incr or incrBy.async incr(key: string, increment: number = 1): Promise<RedisOperationResult<number>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); if (increment === 1) { return await this.client.incr(key); } else { return await this.client.incrBy(key, increment); } }); }