Redis MCP Server

Redis MCP servers enable AI models to interact with Redis databases, providing capabilities for key-value operations, caching, pub/sub messaging, and high-performance data structures.

GitHub starsnpm versionnpm downloads

Overview

The MCP Redis Server enables AI models to interact with Redis, the world's most popular in-memory data structure store. Redis is widely used for caching, real-time analytics, session management, and message queuing, making it essential for high-performance applications.

Official Server:

Developed and maintained by Anthropic

Key Features

High-Performance Operations

Lightning-fast key-value operations with in-memory data storage

🔑

Flexible Key Management

Set, get, delete, and search keys with pattern matching support

TTL & Expiration

Automatic key expiration with Time-To-Live configuration

💾

Caching & Sessions

Ideal for caching, session storage, and rate limiting

Available Tools

Quick Reference

ToolPurposeCategory
redis_getRetrieve value by keyRead
redis_setStore key-value pairWrite
redis_deleteRemove one or more keysWrite
redis_listList keys by patternDiscovery

Detailed Usage

redis_get

Retrieve the value associated with a Redis key.

use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_get",
  arguments: {
    key: "user:1234:profile"
  }
});

Returns the stored value or null if key doesn't exist.

redis_set

Store a key-value pair in Redis with optional expiration time.

// Set a simple key-value pair
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: "session:abc123",
    value: JSON.stringify({ userId: 1234, role: "admin" })
  }
});

// Set with 1-hour expiration (TTL)
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: "cache:trending",
    value: JSON.stringify({ items: [...] }),
    expireSeconds: 3600
  }
});

TTL automatically removes keys after expiration.

redis_delete

Delete one or more keys from Redis.

// Delete a single key
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_delete",
  arguments: {
    key: "temp:data"
  }
});

// Delete multiple keys at once
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_delete",
  arguments: {
    key: ["cache:page1", "cache:page2", "cache:page3"]
  }
});

Returns the number of keys successfully deleted.

redis_list

List all keys matching a pattern using Redis glob-style patterns.

// List all keys
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_list",
  arguments: {
    pattern: "*"
  }
});

// List keys with specific prefix
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_list",
  arguments: {
    pattern: "user:*"
  }
});

// List session keys
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_list",
  arguments: {
    pattern: "session:*"
  }
});

Supports glob patterns: * (any chars), ? (single char), [abc] (char set)

Installation

{
  "mcpServers": {
    "redis": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-redis",
        "redis://localhost:6379"
      ]
    }
  }
}

Custom Connection:

Replace redis://localhost:6379 with your Redis connection URL. For password-protected instances, use redis://:password@host:port

Common Use Cases

1. Session Management

Store user sessions with automatic expiration:

// Store session with 24-hour expiration
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: "session:user123",
    value: JSON.stringify({
      userId: 123,
      loginTime: Date.now(),
      permissions: ["read", "write"]
    }),
    expireSeconds: 86400  // 24 hours
  }
});

2. Caching API Responses

Cache expensive API calls to improve performance:

// Cache API response for 5 minutes
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: "api:weather:london",
    value: JSON.stringify(weatherData),
    expireSeconds: 300
  }
});

3. Rate Limiting

Track API request counts per user:

// Increment request counter
const key = `ratelimit:${userId}:${currentMinute}`;
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: key,
    value: requestCount.toString(),
    expireSeconds: 60
  }
});

4. Temporary Data Storage

Store temporary processing results:

// Store job results for 1 hour
use_mcp_tool({
  server_name: "redis",
  tool_name: "redis_set",
  arguments: {
    key: `job:${jobId}:result`,
    value: JSON.stringify(processingResult),
    expireSeconds: 3600
  }
});

Connection String Format

The Redis MCP server accepts standard Redis connection URLs:

  • Local: redis://localhost:6379
  • With password: redis://:password@host:6379
  • Custom database: redis://host:6379/2
  • TLS/SSL: rediss://host:6379
  • With auth & DB: redis://:password@host:6379/1

Sources