set_add
Add members to a Redis set using a specified key. Accepts single or multiple members for efficient data management within Redis MCP server.
Instructions
添加集合成员
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | 集合键名 | |
| members | Yes | 要添加的成员或成员数组 |
Implementation Reference
- src/services/mcpService.ts:1092-1104 (handler)MCP tool handler for set_add: ensures Redis is connected, executes SADD via RedisService, returns JSON result as text content.private async handleSetAdd(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.sadd(args.key, args.members); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:352-373 (registration)Registers the set_add tool with MCP server, including name, description, and input schema validating key (string) and members (string or string array).{ name: 'set_add', description: '添加集合成员', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '集合键名' }, members: { oneOf: [ { type: 'string', description: '成员' }, { type: 'array', items: { type: 'string' }, description: '成员数组' } ], description: '要添加的成员或成员数组' } }, required: ['key', 'members'] } },
- src/services/mcpService.ts:670-671 (registration)Switch case in MCP CallToolRequestHandler that dispatches set_add tool calls to the handleSetAdd method.case 'set_add': return await this.handleSetAdd(args);
- src/services/redisService.ts:380-390 (helper)RedisService.sadd method: wraps ioredis client.sAdd for adding set members (handles string or array), executed within error-handling executeCommand.async sadd(key: string, members: string | string[]): Promise<RedisOperationResult<number>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); if (Array.isArray(members)) { return await this.client.sAdd(key, members); } else { return await this.client.sAdd(key, members); } }); }