 redis客户端
redis客户端
  x/redisClient组件:redis客户端。可以执行redis命令。
# 配置
该组件允许通关过server字段复用共享的redis连接客户端。参考组件连接复用 。
| 字段 | 类型 | 说明 | 默认值 | 
|---|---|---|---|
| server | string | redis服务器地址,格式:host:port | 无 | 
| password | string | Redis密码 | 无 | 
| poolSize | int | 连接池大小 | 0 | 
| db | int | Redis数据库索引 | 0 | 
| cmd | string | Redis命令,支持带参数格式(如"SET key value")和${}变量替换 | 无 | 
| paramsExpr 已弃用 | string | 动态参数表达式(已弃用,建议使用params字段) | 无 | 
| params | array | 命令参数,支持${}变量替换和组件配置变量 | 无 | 
# 配置说明
# cmd字段
cmd字段支持两种格式:
- 单独命令:如"SET"、"GET"、"HSET"等,参数通过params字段提供
- 带参数命令:如"SET key value"、"HSET myhash field1 value1"等,命令和参数一起提供
# params字段
params字段支持:
- 静态参数:直接提供参数值,如["key1", "value1"]
- 动态参数:使用${}语法进行变量替换,如["${metadata.key}", "${data}"]
- 组件配置变量:支持所有组件配置变量语法
# Relation Type
- Success: 执行成功,把消息发送到Success链
- Failure: 执行失败,把消息发送到Failure链
# 执行结果
执行结果替换到msg.Data,流转到下一个节点。
# 配置示例
# 示例1:使用单独命令和params参数
{
  "id": "s5",
  "type": "x/redisClient",
  "name": "保存到redis",
  "debugMode": true,
  "configuration": {
    "server": "192.168.1.1:6379",
    "cmd": "SET",
    "params": ["${metadata.key}", "${msg.value}"],
    "poolSize": 10
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 示例2:使用带参数的命令格式
{
  "id": "s6",
  "type": "x/redisClient",
  "name": "设置哈希字段",
  "debugMode": true,
  "configuration": {
    "server": "192.168.1.1:6379",
    "cmd": "HSET ${msg.hashKey} ${msg.field}",
    "params": ["${data}"],
    "poolSize": 10
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 示例3:完整命令(不使用params)
{
  "id": "s7",
  "type": "x/redisClient",
  "name": "完整SET命令",
  "debugMode": true,
  "configuration": {
    "server": "192.168.1.1:6379",
    "cmd": "SET ${metadata.key} ${metadata.value}",
    "poolSize": 10
  }
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 应用示例
应用示例参考:redisClient (opens new window)
{
  "ruleChain": {
    "id":"chain_msg_type_switch",
    "name": "测试规则链-msgTypeSwitch",
    "root": false,
    "debugMode": false
  },
  "metadata": {
    "nodes": [
      {
        "id": "s1",
        "type": "msgTypeSwitch",
        "name": "过滤",
        "debugMode": true
      },
      {
        "id": "s2",
        "type": "log",
        "name": "记录日志1",
        "debugMode": true,
        "configuration": {
          "jsScript": "return msgType+':s2--'+JSON.stringify(msg);"
        }
      },
      {
        "id": "s3",
        "type": "log",
        "name": "记录日志2",
        "debugMode": true,
        "configuration": {
          "jsScript": "return msgType+':s3--'+JSON.stringify(msg);"
        }
      },
      {
        "id": "s5",
        "type": "x/redisClient",
        "name": "保存到redis",
        "debugMode": true,
        "configuration": {
          "cmd": "SET",
          "params": ["${msg.key1}", "${msg.value1}"],
          "poolSize": 10,
          "Server": "192.168.1.1:6379"
        }
      },
	{
        "id": "s6",
        "type": "x/redisClient",
        "name": "保存到redis",
        "debugMode": true,
        "configuration": {
          "cmd": "SET",
          "params": ["${msg.key2}", "${msg.value2}"],
          "poolSize": 10,
          "Server": "192.168.1.1:6379"
        }
      }
    ],
    "connections": [
      {
        "fromId": "s1",
        "toId": "s2",
        "type": "TEST_MSG_TYPE1"
      },
      {
        "fromId": "s1",
        "toId": "s3",
        "type": "TEST_MSG_TYPE2"
      },
      {
        "fromId": "s3",
        "toId": "s5",
        "type": "Success"
      },
  		{
        "fromId": "s2",
        "toId": "s6",
        "type": "Success"
      }
    ]
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
在 GitHub 上编辑此页  (opens new window)
  上次更新: 2025/09/02, 11:02:23
