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
| Name | Required | Description | Default |
|---|---|---|---|
| fields | Yes | Field-value pairs to set | |
| key | Yes | Hash key |
Implementation Reference
- src/tools/hmset_tool.ts:27-38 (handler)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}`); } }
- src/tools/hmset_tool.ts:8-19 (schema)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'] };
- src/tools/tool_registry.ts:25-39 (registration)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(), ];
- src/interfaces/types.ts:6-9 (schema)TypeScript type definition for HMSetArgs used in hmset tool validation.export interface HMSetArgs { key: string; fields: Record<string, string>; }
- src/tools/hmset_tool.ts:21-25 (helper)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'; }