Skip to main content
Glama

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
NameRequiredDescriptionDefault
keyYes键名
decrementNo减量值(可选,默认为 1)

Implementation Reference

  • 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']
      }
  • 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)
          }
        ]
      };
    }
  • 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);
        }
      });
    }

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