Skip to main content
Glama

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
NameRequiredDescriptionDefault
countNo弹出数量(可选)
keyYes列表键名

Implementation Reference

  • The MCP tool handler for 'list_lpop' that ensures connection and delegates to RedisService.lpop
    private 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) } ] }; }
  • 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'] } },
  • Switch case in the central CallToolRequestSchema handler that dispatches to the list_lpop handler
    case 'list_lpop': return await this.handleListLpop(args);
  • The underlying RedisService.lpop method that implements the LPOP logic with count support using loop for compatibility
    async 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)}` }; } }

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

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