redisClient
x/redisClient
component: redis client. Can execute redis commands.
# Configuration
This component allows the reuse of shared connection clients through the server
field. See Component Connection Reuse for reference.
Field | Type | Description | Default value |
---|---|---|---|
server | string | Redis server address | None |
password | string | Password | None |
poolSize | int | Connection pool size | 0 |
db | int | Database | None |
cmd | string | redis execution command, such as: SET/GET/Del, can using Component Configuration Variables. | None |
paramsExpr v0.23.0+ | string | Dynamic parameter expression. | 无 |
params | array | execution command parameters, can using Component Configuration Variables. | None |
If both paramsExpr
and params
exist, paramsExpr
takes precedence. For example: ["myhash2", "field1", "value1"]
Expressions can be translated using the following variables:
- Access the message ID via the
id
variable. - Access the message timestamp via the
ts
variable. - Access the raw content of the message via the
data
variable. - Access the message body via the
msg
variable. If the message'sdataType
is JSON, you can access fields usingmsg.XX
. For example:msg.values;
- Access message metadata via the
metadata
variable. For example:metadata.customerName
- Access the message type via the
type
variable. - Access the data type via the
dataType
variable.
Examples of expressions:
upper(msg.name)
metaData.productType
msg.temperature + 50
replace(metaData.productType, 'oldValue', 'newValue')
For more expression syntax, refer to the expr documentation (opens new window).
# Relation Type
- Success: Execution successful, send the message to the
Success
chain - Failure: Execution failed, send the message to the
Failure
chain
# Execution result
The execution result replaces msg.Data and passes to the next node.
# Configuration example
{
"id": "s5",
"type": "x/redisClient",
"name": "Save to redis",
"debugMode": true,
"configuration": {
"cmd": "SET",
"params": ["${key}", "${msg.data}"],
"poolSize": 10,
"Server": "192.168.1.1:6379"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# Application example
Application example reference: redisClient (opens new window)
{
"ruleChain": {
"id":"chain_msg_type_switch",
"name": "Test rule chain-msgTypeSwitch",
"root": false,
"debugMode": false
},
"metadata": {
"nodes": [
{
"id": "s1",
"type": "msgTypeSwitch",
"name": "Filter",
"debugMode": true
},
{
"id": "s2",
"type": "log",
"name": "Log 1",
"debugMode": true,
"configuration": {
"jsScript": "return msgType+':s2--'+JSON.stringify(msg);"
}
},
{
"id": "s3",
"type": "log",
"name": "Log 2",
"debugMode": true,
"configuration": {
"jsScript": "return msgType+':s3--'+JSON.stringify(msg);"
}
},
{
"id": "s5",
"type": "x/redisClient",
"name": "Save to redis",
"debugMode": true,
"configuration": {
"cmd": "SET",
"params": ["${key}", "${msg.data}"],
"poolSize": 10,
"Server": "192.168.1.1:6379"
}
},
{
"id": "s6",
"type": "x/redisClient",
"name": "Save to redis",
"debugMode": true,
"configuration": {
"cmd": "SET",
"params": ["${key}", "${value}"],
"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
Edit this page on GitHub (opens new window)
Last Updated: 2024/10/31, 11:41:00