You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
summary: Redis Data Integration keeps Redis in sync with the primary database in near
13
13
real time.
14
14
type: integration
15
15
weight: 100
16
16
---
17
17
18
-
In the example below, the data is captured from the source table named `employee` and is written to the Redis database as a JSON document. When you specify the `data_type` parameter for the job, it overrides the system-wide setting `target_data_type` defined in `config.yaml`.
18
+
The operation code (`opcode`) is a metadata field that indicates the type of operation that generated the change in the source database. It can be useful for tracking changes and understanding the context of the data being processed.
19
+
20
+
The opcode is only available in the [full row format]({{< relref "/integrate/redis-data-integration/data-pipelines/transform-examples/redis-row-format#full" >}}), and can be accessed in the `transform` and `output` sections of the job file.
21
+
22
+
It has one of the following values:
23
+
24
+
- r - Read (applies to only snapshots)
25
+
- c - Create
26
+
- u - Update
27
+
- d - Delete
28
+
- t = Truncate (PostgreSQL specific)
29
+
- m = Message (PostgreSQL specific)
30
+
31
+
32
+
You can add the value of the operation code to the output, and also use it in a conditional expression to modify the behavior of the job. The following examples demonstrate the different use-cases.
33
+
34
+
### Adding the operation code to the output
35
+
36
+
Use the `add_field` transformation to add a new field that contains the value of the `opcode` field from the source data. Note that the fields must be prefixed with `after` to be included in the output.
19
37
20
-
Here, the result will be Redis JSON documents with fields captured from the source table
21
-
(`employeeid`, `firstname`, `lastname`) and also with
22
-
an extra field `my_opcode` added using the `merge` update strategy (see the
for more information). The `opcode` expression refers to the operation code captured from
25
-
the source. This is a database-specific value that indicates which type of operation generated
26
-
the change (insert, update, etc).
27
38
28
39
```yaml
29
40
source:
30
41
schema: public
31
42
table: employee
32
43
row_format: full
44
+
33
45
transform:
46
+
# add the operation code to the data
34
47
- uses: add_field
35
48
with:
36
-
field: after.my_opcode
49
+
field: after.operation_code
37
50
expression: opcode
38
51
language: jmespath
39
-
output:
40
-
- uses: redis.write
52
+
```
53
+
54
+
55
+
### Filtering operation by output code.
56
+
57
+
In some cases you may want to ignore certain operations (for example, you may not be interested in deletions). Use the `filter` transformation to filter out any operations you don't need to process.
58
+
59
+
```yaml
60
+
source:
61
+
schema: public
62
+
table: employee
63
+
row_format: full
64
+
65
+
transform:
66
+
- uses: filter
67
+
with:
68
+
expression: opcode != 'd'
69
+
language: jmespath
70
+
```
71
+
72
+
### Modifying the output based on the operation code
73
+
74
+
The previous example filters out specific operations, but you can also modify the output based on the operation code. For example, you can add a new field that tracks the status of the record based on the operation code.
75
+
76
+
Note that when a source record is deleted, you must modify the value of the `opcode` field if you want to prevent the corresponding record in the target database from being removed automatically.
77
+
78
+
```yaml
79
+
source:
80
+
schema: public
81
+
table: employee
82
+
row_format: full
83
+
84
+
transform:
85
+
- uses: add_field
41
86
with:
42
-
data_type: json
43
-
mapping:
44
-
- employeeid
45
-
- firstname
46
-
- lastname
47
-
- my_opcode
48
-
connection: target
49
-
on_update: merge
50
-
```
87
+
fields:
88
+
# Here you set the value of the field based on the value of the opcode field
Copy file name to clipboardExpand all lines: content/integrate/redis-data-integration/data-pipelines/transform-examples/redis-row-format.md
+1-10Lines changed: 1 addition & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ With `row_format: full` the input value is a JSON object with the following stru
63
63
- `key`- An object containing the attributes of the primary key. For example, `key.id` will give you the value of the `id` column as long as it is part of the primary key.
64
64
- `before`- An object containing the previous value of the row.
65
65
- `after`- An object containing the current value of the row.
66
-
- `opcode`- The operation code. Different databases use different values for the operation code. See [operation code values]({{< relref "#operation-codes" >}}) below for more information.
66
+
- `opcode`- The operation code. See [Using the operation code]({{< relref "/integrate/redis-data-integration/data-pipelines/transform-examples/redis-opcode-example" >}}) for more information about the possible opcode values and how to use them.
0 commit comments