Flow ServerStarter
存储与消息

Redis 通用命令

type redisCommand

在设计器中打开 ↗

hash / list / publish / 计数器等命令

使用说明

要点:Redis 通用命令:hash / list / publish / 计数器等。field、start、end、expire 会写入对应 CamelRedis Header。
可选依赖该节点需要宿主额外引入 camel-spring-redis-starter,否则部署相关流程会在 Camel 启动路由阶段失败并回滚。

属性

字段类型必填默认值说明
command
命令
枚举 必填 GET
可选值:SET、GET、DEL、EXISTS、EXPIRE、INCR、DECR、HSET、HGET、HDEL、LPUSH、RPUSH、LPOP、RPOP、LRANGE、PUBLISH
redisTemplate
RedisTemplate Bean
文本 可选 —
key
Key 表达式
表达式 必填 —
value
Value 表达式
表达式 可选 —
field
Hash Field 表达式
表达式 可选 —
start
LRANGE 起始下标
表达式 可选 —
end
LRANGE 结束下标
表达式 可选 —
expire
过期时间(秒)
表达式 可选 —

示例流程

可直接保存为 demo-redisCommand.json 并部署;非入口节点默认套了一个 REST 入口。

Flow JSON
{
  "id": "demo-redisCommand",
  "desc": "Redis 通用命令 示例",
  "group": "示例/存储与消息",
  "schemaVersion": 1,
  "nodes": [
    {
      "id": "n1",
      "type": "rest",
      "props": {
        "method": "POST",
        "path": "/demo/redisCommand",
        "desc": "示例入口"
      }
    },
    {
      "type": "redisCommand",
      "props": {
        "command": "HSET",
        "key": {
          "lang": "simple",
          "script": "demo:hash"
        },
        "field": {
          "lang": "constant",
          "script": "userId"
        },
        "value": {
          "lang": "simple",
          "script": "${header.id}"
        },
        "expire": {
          "lang": "constant",
          "script": "3600"
        }
      },
      "id": "n1"
    }
  ]
}
部署这段流程
curl -X POST 'http://localhost:8086/flow' \
  -H 'Content-Type: application/json' \
  -H 'X-Flow-Token: change-me' \
  --data-binary @demo-redisCommand.json

调用方式

调用示例
curl -X POST 'http://localhost:8086/demo/redisCommand' \
  -H 'Content-Type: application/json' \
  -d '{"id":1001}'

相关节点