Skip to main content
Glama

key_expire

Set expiration time for Redis keys to automatically remove data after a specified duration, managing memory and data lifecycle.

Instructions

设置键过期时间

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYes键名
secondsYes过期时间(秒)

Implementation Reference

  • The main handler function for the 'key_expire' MCP tool. It ensures Redis connection and calls RedisService.expire to set key expiration time.
    private async handleKeyExpire(args: any) {
      this.ensureRedisConnection();
      const result = await this.redisService!.expire(args.key, args.seconds);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2)
          }
        ]
      };
    }
  • The input schema definition for the 'key_expire' tool, registered in the ListTools response.
    {
      name: 'key_expire',
      description: '设置键过期时间',
      inputSchema: {
        type: 'object',
        properties: {
          key: { type: 'string', description: '键名' },
          seconds: { type: 'number', description: '过期时间(秒)' }
        },
        required: ['key', 'seconds']
      }
    },
  • The dispatch/registration case in the CallToolRequestHandler switch statement that routes 'key_expire' calls to the handler.
    case 'key_expire':
      return await this.handleKeyExpire(args);
  • Supporting utility method in RedisService that implements the actual Redis EXPIRE command via the redis client.
    async expire(key: string, seconds: number): Promise<RedisOperationResult<boolean>> {
      return this.executeCommand(async () => {
        if (!this.client) throw new Error('Redis client not initialized');
        const result = await this.client.expire(key, seconds);
        return Boolean(result);
      });
    }

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