Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

hmset

Set multiple hash fields to specific values in a Redis database using a single command, streamlining data updates and improving efficiency in hash management.

Instructions

Set multiple hash fields to multiple values

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsYesField-value pairs to set
keyYesHash key

Implementation Reference

  • The execute method implements the core hmset logic using Redis client.hSet(key, fields).
    async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> {
      if (!this.validateArgs(args)) {
        return this.createErrorResponse('Invalid arguments for hmset');
      }
    
      try {
        await client.hSet(args.key, args.fields);
        return this.createSuccessResponse('Hash fields set successfully');
      } catch (error) {
        return this.createErrorResponse(`Failed to set hash fields: ${error}`);
      }
    }
  • JSON schema defining the input parameters for the hmset tool: key (string) and fields (object).
    inputSchema = {
      type: 'object',
      properties: {
        key: { type: 'string', description: 'Hash key' },
        fields: { 
          type: 'object',
          description: 'Field-value pairs to set',
          additionalProperties: { type: 'string' }
        }
      },
      required: ['key', 'fields']
    };
  • Registers HMSetTool as part of the default tools in ToolRegistry by instantiating and adding to the registry.
    const defaultTools = [
      new HMSetTool(),
      new HGetTool(),
      new HGetAllTool(),
      new ScanTool(),
      new SetTool(),
      new GetTool(),
      new DelTool(),
      new ZAddTool(),
      new ZRangeTool(),
      new ZRangeByScoreTool(),
      new ZRemTool(),
      new SAddTool(),
      new SMembersTool(),
    ];
  • TypeScript type definition for HMSetArgs used in hmset tool validation.
    export interface HMSetArgs {
      key: string;
      fields: Record<string, string>;
    }
  • Validates input arguments match HMSetArgs structure before execution.
    validateArgs(args: unknown): args is HMSetArgs {
      return typeof args === 'object' && args !== null &&
        'key' in args && typeof (args as any).key === 'string' &&
        'fields' in args && typeof (args as any).fields === 'object';
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

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/farhankaz/redis-mcp'

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