string_set
Store and manage string key-value pairs in Redis with optional expiration. Simplify data storage and retrieval using structured input parameters for efficient database operations.
Instructions
设置字符串键值
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expireSeconds | No | 过期时间(秒)(可选) | |
| key | Yes | 键名 | |
| value | Yes | 值 |
Implementation Reference
- src/services/mcpService.ts:820-832 (handler)MCP tool handler for 'string_set'. Ensures Redis connection and delegates to RedisService.set with key, value, and optional expireSeconds.private async handleStringSet(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.set(args.key, args.value, args.expireSeconds); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:102-114 (schema)Tool registration entry in listTools response, defining name, description, and input schema for validation.{ name: 'string_set', description: '设置字符串键值', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '键名' }, value: { type: 'string', description: '值' }, expireSeconds: { type: 'number', description: '过期时间(秒)(可选)' } }, required: ['key', 'value'] } },
- src/services/redisService.ts:115-127 (helper)Core Redis SET operation implementation that performs the actual Redis client.set call, handling optional expiration.async set(key: string, value: string, expireSeconds?: number): Promise<RedisOperationResult<string>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); if (expireSeconds !== undefined) { const result = await this.client.set(key, value, { EX: expireSeconds }); return result || 'OK'; } else { const result = await this.client.set(key, value); return result || 'OK'; } }); }