Skip to content

Commit 922e5cd

Browse files
committed
docs: Added TTL section
1 parent fee8d40 commit 922e5cd

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

docs/guide/src/docs/asciidoc/sink.adoc

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,39 @@ value.converter.schemas.enable = <true|false> <1>
266266
----
267267
<1> Set to `true` if the JSON record structure has an attached schema
268268

269+
[[_sink_ttl]]
270+
== TTL (Time To Live)
271+
272+
The {name} supports setting TTL (Time To Live) for Redis keys to automatically expire data after a specified duration. TTL can be configured globally for all keys or per-message using Kafka headers.
273+
274+
=== Global TTL Configuration
275+
276+
Set a global TTL for all keys using the `redis.key.ttl` configuration property:
277+
278+
[source,properties]
279+
----
280+
redis.key.ttl = 3600 # TTL in seconds (1 hour)
281+
----
282+
283+
=== Per-Message TTL
284+
285+
Include a `redis.key.ttl` header in your Kafka messages to set TTL for individual records:
286+
287+
[source,java]
288+
----
289+
ProducerRecord<String, String> record = new ProducerRecord<>("topic", "key", "value");
290+
record.headers().add("redis.key.ttl", "1800".getBytes()); // 30 minutes
291+
----
292+
293+
=== TTL Behavior
294+
295+
* TTL is applied using the Redis `EXPIRE` command after data is written
296+
* Per-message TTL headers take precedence over global configuration
297+
* TTL applies to all Redis data types
298+
* For collection types (STREAM, LIST, SET, ZSET, TIMESERIES), TTL is applied to the collection key
299+
* Invalid TTL values are logged and ignored
300+
* TTL value of -1 (default) means no expiration
301+
269302
[[_sink_config]]
270303
== Configuration
271304

@@ -275,12 +308,14 @@ connector.class = com.redis.kafka.connect.RedisSinkConnector
275308
topics = <Kafka topic> <1>
276309
redis.uri = <Redis URI> <2>
277310
redis.type = <HASH|SET|JSON|STREAM|LIST|SET|ZSET|TIMESERIES> <3>
278-
key.converter = <Key converter> <4>
279-
value.converter = <Value converter> <5>
311+
redis.key.ttl = <TTL in seconds> <4>
312+
key.converter = <Key converter> <5>
313+
value.converter = <Value converter> <6>
280314
----
281315
<1> Kafka topics to read messsages from.
282316
<2> <<_sink_redis_client,Redis URI>>.
283317
<3> <<_sink_redis_command,Redis command>>.
284-
<4> <<_sink_key,Key converter>>.
285-
<5> <<_sink_value,Value converter>>.
318+
<4> <<_sink_ttl,TTL in seconds>> (optional, default: -1 for no expiration).
319+
<5> <<_sink_key,Key converter>>.
320+
<6> <<_sink_value,Value converter>>.
286321

0 commit comments

Comments
 (0)