本页内容
Sommatic 文档
打开控制台

Redis - Command

在 Redis 键值存储上执行命令。

以 Markdown 查看
在以下应用中打开
集成 可用 integrations.redis.command 版本 1.0.0 执行方式: async

发送一条原始 Redis 命令(GET、SET、HGET、LPUSH、DEL 等)及其参数,并将 Redis 回复放在 result 中返回。

连接你的 Redis 实例,自动化缓存和数据操作。可发送任意带参数的 Redis 命令,从简单的键值读取到复杂的数据结构操作。

操作:

  • GET / SET / MGET / MSET: 读写字符串值,支持批量操作。
  • HGET / HSET / HGETALL: 操作哈希表(字段-值对)。
  • LPUSH / RPUSH / LPOP / LRANGE: 管理有序列表。
  • SADD / SMEMBERS / SINTER: 操作集合及求交集。
  • ZADD / ZRANGE / ZRANGEBYSCORE: 带分值的有序集合。
  • DEL / EXISTS / TTL / EXPIRE: 键的生命周期与过期管理。
  • INCR / DECR: 原子计数器。
  • PUBLISH: 向频道发布消息。

工作原理

  1. 解析节点配置中的表达式。connection_id、command 为空时从输入项读取;args 缺失或为空数组时同样从输入项读取。
  2. 解析连接:connection_id 中的 redis:// URL、connection-string 凭据(客户端支持的任意 URL,包括 rediss://),或包含 host、port(默认 6379)和可选 password 的 basic-auth / object 凭据。
  3. 将 command 转为大写,丢弃 null / undefined 参数,其余参数用 String() 转换后原样发送命令。
  4. 断开连接,并经 out 返回包含回复的 { result }:根据命令不同为字符串、数字、null 或数组。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-cache-order",
  "label": "Read cached order",
  "operator_slug": "integrations.redis.command",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "command": "GET",
    "args": [
      "order:{{ $json.order_id }}"
    ]
  }
}

配置

connection_id string 必填

Redis 实例的凭据。接受 `connection-string`(redis:// URI)或 `basic-auth`(密码 + 主机 + 端口)类型的凭据。

command string 必填 支持表达式

要执行的 Redis 命令(例如 GET、SET、HGET、LPUSH、DEL)。

args array 可选

命令参数(例如 key、value、字段名)。

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

args
每个参数都会用 String() 转换:对象会变成 [object Object]。传入 JSON 值前请先序列化为字符串。
connection_id
结构化凭据会生成不含 TLS 和用户名的 redis:// URL。需要 TLS 或 ACL 用户时,请将完整 URL 保存为 connection-string 凭据。

输出端口

out 默认

Redis 已回复。对不存在的键执行 GET 也从这里输出,result 为 null。

数据
{
  "result": "{\"status\":\"open\",\"total\":129.99}"
}
error

校验、凭据解析、连接或命令执行失败。

数据
{
  "error": "WRONGTYPE Operation against a key holding the wrong kind of value"
}

在表达式中

后续节点可通过 $("Redis - Command").item.json.<路径> 读取此节点输出中的内容(请把 Redis - Command 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Redis - Command").item.json.resultobject= "{\"status\":\"open\",\"total\":129.99}"Redis 命令响应

错误

消息 端口 原因与处理
connection_id is required error 配置和输入项中都没有凭据。
command is required error command 为空。
Credential <connection_id> (type '<type>') missing host error 结构化凭据缺少 host。
ERR <Redis error message> error Redis 拒绝了该命令(未知命令、参数数量错误等),错误信息原样传递。

输入契约

connection_id string 必填
command string 必填
args array 可选

输出契约

result object 可选

Redis 命令响应

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "integrations.redis.command",
  "name": "Redis - Command",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Execute commands on a Redis key-value store.\n\n  Connect your Redis instance and automate cache and data operations. Send any Redis command with arguments — from simple key-value reads to complex data structure manipulation.\n\n  **Operations:**\n  - **GET / SET / MGET / MSET:** Read and write string values, bulk operations.\n  - **HGET / HSET / HGETALL:** Work with hash maps (field-value pairs).\n  - **LPUSH / RPUSH / LPOP / LRANGE:** Manage ordered lists.\n  - **SADD / SMEMBERS / SINTER:** Work with sets and intersections.\n  - **ZADD / ZRANGE / ZRANGEBYSCORE:** Sorted sets with scoring.\n  - **DEL / EXISTS / TTL / EXPIRE:** Key lifecycle and expiration management.\n  - **INCR / DECR:** Atomic counters.\n  - **PUBLISH:** Publish messages to channels.",
  "capabilities": [
    "kv",
    "cache",
    "redis",
    "database"
  ],
  "group": [
    {
      "key": "redis",
      "name": "Redis",
      "icon_url": "/icons/integrations/redis/redis.svg"
    }
  ],
  "icon_url": "/icons/integrations/redis/redis.svg",
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Redis Credential",
        "description": "Credential for your Redis instance. Accepts credentials of type `connection-string` (redis:// URI) or `basic-auth` (password + host + port).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "connection-string",
            "basic-auth"
          ],
          "types": [
            "redis"
          ]
        }
      },
      "command": {
        "type": "string",
        "title": "Command",
        "description": "Redis command to execute (e.g., GET, SET, HGET, LPUSH, DEL).",
        "format": "expression"
      },
      "args": {
        "type": "array",
        "title": "Arguments",
        "description": "Command arguments (e.g., key, value, field name)."
      }
    },
    "required": [
      "connection_id",
      "command"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "command": {
        "type": "string"
      },
      "args": {
        "type": "array"
      }
    },
    "required": [
      "connection_id",
      "command"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "Redis command response"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "Command result",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Command execution error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "fast-io"
  ],
  "tags": [
    "cache",
    "kv"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
凭据
在服务器端根据 connection_id 解析,密钥不会进入工作流。
能力
kvcacheredisdatabase
标签
cachekv

说明与限制

  • 每次运行都会新建并关闭连接,节点不会重试。INCR、LPUSH 等非幂等命令每次执行只运行一次。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档