hash_get
Retrieve specific field values from a Redis hash key using the Redis MCP server, simplifying efficient data access and management for database operations.
Instructions
获取哈希字段
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | 字段名 | |
| key | Yes | 哈希键名 |
Implementation Reference
- src/services/mcpService.ts:956-967 (handler)The primary handler function for the 'hash_get' MCP tool. It ensures a Redis connection, retrieves the hash field value using RedisService.hget(key, field), and returns the result as formatted JSON text content.private async handleHashGet(args: any) { this.ensureRedisConnection(); const result = await this.redisService!.hget(args.key, args.field); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] };
- src/services/mcpService.ts:224-235 (schema)The tool schema definition including name, description, and input schema (requires 'key' and 'field' strings) as returned by ListTools.{ name: 'hash_get', description: '获取哈希字段', inputSchema: { type: 'object', properties: { key: { type: 'string', description: '哈希键名' }, field: { type: 'string', description: '字段名' } }, required: ['key', 'field'] } },
- src/services/mcpService.ts:650-651 (registration)The dispatch case in the CallToolRequest handler that routes 'hash_get' calls to the handleHashGet method.case 'hash_get': return await this.handleHashGet(args);
- src/services/redisService.ts:242-247 (helper)The supporting RedisService.hget method that performs the actual Redis HGET operation via the redis client and wraps it in error handling.async hget(key: string, field: string): Promise<RedisOperationResult<string | null>> { return this.executeCommand(async () => { if (!this.client) throw new Error('Redis client not initialized'); const result = await this.client.hGet(key, field); return result || null; });