Redis数据库
一个提供访问Redis数据库的模型上下文协议服务器。该服务器通过一系列标准化工具使大语言模型能够与Redis键值存储进行交互。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"redis": {
"args": [
"-y",
"@modelcontextprotocol/server-redis",
"REDIS_URL"
],
"command": "npx"
}
}
}
该服务需要配置环境变量:REDIS_URL
可用工具 (13 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
hmset 2 个参数 需填 2 项
Set multiple hash fields to multiple values
必填参数:fields、key
hget 2 个参数 需填 2 项
Get the value of a hash field
必填参数:field、key
hgetall 1 个参数 需填 1 项
Get all the fields and values in a hash
必填参数:key
scan 2 个参数 需填 1 项
Scan Redis keys matching a pattern
必填参数:pattern
set 4 个参数 需填 2 项
Set string value with optional NX (only if not exists) and PX (expiry in milliseconds) options
必填参数:key、value
get 1 个参数 需填 1 项
Get string value
必填参数:key
del 1 个参数 需填 1 项
Delete a key
必填参数:key
zadd 2 个参数 需填 2 项
Add one or more members to a sorted set
必填参数:key、members
zrange 4 个参数 需填 3 项
Return a range of members from a sorted set by index
必填参数:key、start、stop
zrangebyscore 4 个参数 需填 3 项
Return members from a sorted set with scores between min and max
必填参数:key、min、max
zrem 2 个参数 需填 2 项
Remove one or more members from a sorted set
必填参数:key、members
sadd 2 个参数 需填 2 项
Add one or more members to a set
必填参数:key、members
smembers 1 个参数 需填 1 项
Get all members in a set
必填参数:key
服务介绍
Redis
一个提供访问 Redis 数据库的模型上下文协议服务器。此服务器通过一组标准化工具使 LLM 能够与 Redis 键值存储进行交互。
先决条件
- 必须安装并运行 Redis 服务器
- 下载 Redis
- 对于 Windows 用户:使用 Windows Subsystem for Linux (WSL) 或 Memurai(兼容 Redis 的 Windows 服务器)
- 默认端口:6379
常见问题及解决方案
连接错误
ECONNREFUSED
- 原因:Redis 服务器未运行或无法访问
- 解决方案:
- 验证 Redis 是否正在运行:
redis-cli ping应返回 "PONG" - 检查 Redis 服务状态:
systemctl status redis(Linux)或brew services list(macOS) - 确保默认端口(6379)未被防火墙阻止
- 验证 Redis URL 格式:
redis://hostname:port
- 验证 Redis 是否正在运行:
服务器行为
- 服务器实现了带有最大重试次数 5 次的指数退避策略
- 初始重试延迟:1 秒,最大延迟:30 秒
- 服务器将在达到最大重试次数后退出,以防止无限重连循环
组件
工具
-
set
- 设置 Redis 键值对,并可选设置过期时间
- 输入:
key(字符串):Redis 键value(字符串):要存储的值expireSeconds(数字, 可选):过期时间(秒)
-
get
- 从 Redis 中根据键获取值
- 输入:
key(字符串):要检索的 Redis 键
-
delete
- 从 Redis 中删除一个或多个键
- 输入:
key(字符串 | 字符串数组):要删除的单个键或键数组
-
list
- 列出与模式匹配的 Redis 键
- 输入:
pattern(字符串, 可选):用于匹配键的模式(默认:*)
与 Claude Desktop 一起使用
要将此服务器与 Claude Desktop 应用程序一起使用,请在您的 claude_desktop_config.json 文件的 "mcpServers" 部分添加以下配置:
Docker
- 在 macOS 上运行 Docker 时,如果服务器在主机网络上运行(例如 localhost),请使用 host.docker.internal
- 可以作为参数指定 Redis URL,默认为 "redis://localhost:6379"
{
"mcpServers": {
"redis": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"mcp/redis",
"redis://host.docker.internal:6379"]
}
}
}
NPX
{
"mcpServers": {
"redis": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-redis",
"redis://localhost:6379"
]
}
}
}
构建
Docker:
docker build -t mcp/redis -f src/redis/Dockerfile .
许可证
该 MCP 服务器基于 MIT 许可证发布。这意味着您可以自由使用、修改和分发软件,但需遵守 MIT 许可证的条款和条件。有关更多详细信息,请参阅项目仓库中的 LICENSE 文件。