Skip to main content
Glama
farhankaz

Redis MCP Server

by farhankaz

set

Store a string value in Redis using MCP, with options to set expiry in milliseconds and ensure the key does not already exist.

Instructions

Set string value with optional NX (only if not exists) and PX (expiry in milliseconds) options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to set
nxNoOnly set if key does not exist
pxNoSet expiry in milliseconds
valueYesValue to set

Implementation Reference

  • The execute method implements the core logic of the 'set' MCP tool, handling argument validation and executing the Redis SET command with support for NX (set if not exists) and PX (expiration in ms) options.
    async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> { if (!this.validateArgs(args)) { return this.createErrorResponse('Invalid arguments for set'); } try { const options: any = {}; if (args.nx) { options.NX = true; } if (args.px) { options.PX = args.px; } const result = await client.set(args.key, args.value, options); if (result === null) { return this.createSuccessResponse('Key not set (NX condition not met)'); } return this.createSuccessResponse('OK'); } catch (error) { return this.createErrorResponse(`Failed to set key: ${error}`); } }
  • Input schema defining the parameters for the 'set' tool: required key and value strings, optional boolean nx and number px.
    inputSchema = { type: 'object', properties: { key: { type: 'string', description: 'Key to set' }, value: { type: 'string', description: 'Value to set' }, nx: { type: 'boolean', description: 'Only set if key does not exist' }, px: { type: 'number', description: 'Set expiry in milliseconds' } }, required: ['key', 'value'] };
  • Registers the SetTool instance in the ToolRegistry by including it in the defaultTools array and calling registerTool in the loop.
    private registerDefaultTools() { const defaultTools = [ new HMSetTool(), new HGetTool(), new HGetAllTool(), new ScanTool(), new SetTool(), new GetTool(), new DelTool(), new ZAddTool(), new ZRangeTool(), new ZRangeByScoreTool(), new ZRemTool(), new SAddTool(), new SMembersTool(), ]; for (const tool of defaultTools) { this.registerTool(tool); } }

Other Tools

Related Tools

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

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