Skip to main content
Glama

key_info

Retrieve detailed information about Redis keys, including type, TTL, and memory usage, to monitor and manage database performance.

Instructions

获取键信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes键名

Implementation Reference

  • Registration of the 'key_info' tool in MCP server's ListTools response, including name, description, and input schema requiring a 'key' string.
    {
      name: 'key_info',
      description: '获取键信息',
      inputSchema: {
        type: 'object',
        properties: {
          key: { type: 'string', description: '键名' }
        },
        required: ['key']
      }
    },
  • MCP-level handler for 'key_info' tool that ensures Redis connection, calls redisService.getKeyInfo, and formats the response as MCP content.
    private async handleKeyInfo(args: any) {
      this.ensureRedisConnection();
      const result = await this.redisService!.getKeyInfo(args.key);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2)
          }
        ]
      };
    }
  • Core handler implementation in RedisService that retrieves the key's type and TTL using Redis client commands and returns RedisKeyInfo.
    async getKeyInfo(key: string): Promise<RedisOperationResult<RedisKeyInfo>> {
      return this.executeCommand(async () => {
        if (!this.client) throw new Error('Redis client not initialized');
        
        const [type, ttl] = await Promise.all([
          this.client.type(key),
          this.client.ttl(key)
        ]);
        
        return {
          key,
          type,
          ttl
        };
      });
    }
  • TypeScript interface defining the output structure for key information: key name, type, TTL (time to live), and optional size.
    export interface RedisKeyInfo {
      key: string;
      type: string;
      ttl: number;
      size?: number;
    }

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