list_lpop
Remove and return elements from the left side of a Redis list, specifying the key and optional count to manage data efficiently.
Instructions
左侧弹出列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | 弹出数量(可选) | |
| key | Yes | 列表键名 |
Implementation Reference
- src/services/mcpService.ts:1041-1053 (handler)The MCP tool handler for 'list_lpop' that ensures connection and delegates to RedisService.lpopprivate async handleListLpop(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.lpop(args.key, args.count); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }
- src/services/mcpService.ts:314-325 (schema)Input schema definition and registration for the list_lpop tool in the tools list{ name: 'list_lpop', description: '左侧弹出列表', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '列表键名' }, count: { type: 'number', description: '弹出数量(可选)' } }, required: ['key'] } },
- src/services/mcpService.ts:662-663 (registration)Switch case in the central CallToolRequestSchema handler that dispatches to the list_lpop handlercase 'list_lpop': return await this.handleListLpop(args);
- src/services/redisService.ts:310-334 (helper)The underlying RedisService.lpop method that implements the LPOP logic with count support using loop for compatibilityasync lpop(key: string, count?: number): Promise<RedisOperationResult<string | string[] | null>> { try { await this.ensureConnection(); if (!this.client) throw new Error('Redis client not initialized'); if (count !== undefined && count > 0) { // 兼容所有Redis版本:逐个弹出元素 const results: string[] = []; for (let i = 0; i < count; i++) { const item = await this.client.lPop(key); if (item === null) break; results.push(item); } return { success: true, data: results.length === 0 ? null : results }; } else { const result = await this.client.lPop(key); return { success: true, data: result }; } } catch (error) { return { success: false, error: `Redis operation failed: ${error instanceof Error ? error.message : String(error)}` }; } }