Skip to content

Commit e5eba89

Browse files
How to set the key name in target
1 parent 85abc67 commit e5eba89

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
Title: Set the key name in target database
3+
aliases: /integrate/redis-data-integration/ingest/data-pipelines/transform-examples/redis-set-key/
4+
alwaysopen: false
5+
categories:
6+
- docs
7+
- integrate
8+
- rs
9+
- rdi
10+
description: null
11+
group: di
12+
linkTitle: Set the key name in target database
13+
summary: Redis Data Integration keeps Redis in sync with the primary database in near
14+
real time.
15+
type: integration
16+
weight: 30
17+
---
18+
19+
The default key is a combination of the table name, the name of the primary key and the value of the primary key. For example, if the table name is `employee` and the primary key is `employeeid`, the key name will be `employee:employeeid:1` for the record with `employeeid` equal to 1.
20+
21+
When using composite primary keys, the key name will be a combination of the table name, the name of the primary keys and the values of the primary keys. For example, if the table name is `orders` and the primary keys are `orderid` and `customerid`, the key name will be `orders:orderid:1:customerid:2` for the record with `orderid` equal to 1 and `customerid` equal to 2.
22+
23+
24+
If you want to set the key manually you can use the `redis.write` section in the `output` section of the job file. The `key` section allows you to specify a custom key format using the `expression` and `language` parameters. The `expression` parameter allows you to specify a custom key format using the `jmespath` or `sql` language. The `language` parameter allows you to specify the language used in the `expression` parameter. Example:
25+
26+
27+
```yaml
28+
source:
29+
server_name: rdi
30+
db: inventory
31+
table: customers
32+
output:
33+
- uses: redis.write
34+
with:
35+
data_type: hash
36+
key:
37+
expression: concat(['customers', '#', id])
38+
language: jmespath
39+
```
40+
41+
---
42+
43+
{{<note>}}
44+
When using the full row format it is important to reference the attributes you use for building the key name correctly to support both create/update and delete operations. Example:
45+
46+
```yaml
47+
source:
48+
server_name: rdi
49+
db: inventory
50+
table: customers
51+
row_format: full
52+
output:
53+
- uses: redis.write
54+
with:
55+
data_type: hash
56+
key:
57+
# Here we use the operation code to determine the value of the key to ensure that
58+
# delete operations will result in the correct key being deleted
59+
expression: concat(['customers', '#', opcode == 'd' && before.id || after.id])
60+
language: jmespath
61+
```
62+
{{</note>}}

0 commit comments

Comments
 (0)