content/integrate/redis-data-integration/data-pipelines/transform-examples/redis-set-key-name.md
When RDI synchronizes data from your primary database to Redis, it automatically generates key names based on a specific pattern. By default, RDI creates keys using the following format:
tablename:primarykeyname:primarykeyvaluetablename:key1name:key1value:key2name:key2valueExamples
employee with primary key employeeid, a record with employeeid=1 will have the key employee:employeeid:1orders with composite primary keys orderid and customerid, a record with orderid=1 and customerid=2 will have the key orders:orderid:1:customerid:2While the default key naming convention works for many use cases, you may need custom key formats to:
To customize key names, use the key section within the redis.write output configuration. This section requires two parameters:
expression: Defines the custom key format using a supported expression languagelanguage: Specifies the expression language to use (jmespath or sql)name: Custom key name for customers
source:
db: inventory
table: customers
output:
- uses: redis.write
with:
key:
expression: concat(['customers', '#', id])
language: jmespath
When working with the full row format, you need to handle key generation differently to ensure proper behavior across all operation types (create, update, and delete). You must reference attributes correctly to ensure consistent key generation, especially for delete operations where the "after" state is empty. The example below demonstrates how to handle this:
name: Custom key with full row format
source:
db: inventory
table: customers
row_format: full
output:
- uses: redis.write
with:
key:
# Here we use the operation code to determine the value of the key to ensure that
# delete operations will result in the correct key being deleted
expression: concat(['customers', '#', opcode == 'd' && before.id || after.id])
language: jmespath
Proper key naming is essential for effective data organization in Redis. RDI provides:
key section with expression and language parametersBy understanding and utilizing these options, you can ensure your Redis keys are optimally structured for your specific use case, making data retrieval more efficient and your Redis implementation more maintainable.