From 9e08737e7cbf2b5f638e7e5d4076f4e1a46730f0 Mon Sep 17 00:00:00 2001 From: Daniil Gusev Date: Wed, 27 Nov 2024 13:38:46 +0100 Subject: [PATCH] Update Redis Sink example code --- docs/connectors/sinks/redis-sink.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/connectors/sinks/redis-sink.md b/docs/connectors/sinks/redis-sink.md index 1708e048b..9fe0cae28 100644 --- a/docs/connectors/sinks/redis-sink.md +++ b/docs/connectors/sinks/redis-sink.md @@ -68,13 +68,21 @@ when a checkpoint has been committed. By default, `RedisSink` serializes records values to JSON and uses Kafka message keys as Redis keys. -To change that, pass custom functions to the `key_serializer` and `value_serializer` -parameters: +If you want to use a different encoding or change what keys will be inserted to Redis, +you may use `key_serializer` and `value_serializer` callbacks. + +**Example**: + +Use a combination of record's key and value to create a new Redis key, +and convert values using the MessagePack format instead of JSON. ```python from quixstreams import Application from quixstreams.sinks.community.redis import RedisSink +# Assuming "msgpack-python" is installed +import msgpack + app = Application( broker_address="localhost:9092", auto_offset_reset="earliest", @@ -87,9 +95,9 @@ redis_sink = RedisSink( host="", port="", db="", - # Convert records' values to strings before writing to Redis - value_serializer=lambda value: str(value), - # Combine records' keys and values into new keys + # Serialize records' values using msgpack format before writing to Redis + value_serializer=msgpack.dumps, + # Combine a new Redis key from the record's key and value. key_serializer=lambda key, value: f'{key}-{value}', )