From db3205da4162d5414d1fab611c61f0477a29c621 Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Thu, 2 May 2024 23:16:35 +0530 Subject: [PATCH] feat: add json-data type support in redis Signed-off-by: Sai Sankeerth --- src/v0/destinations/redis/transform.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/v0/destinations/redis/transform.js b/src/v0/destinations/redis/transform.js index 23c73f0ba4..4c441e737c 100644 --- a/src/v0/destinations/redis/transform.js +++ b/src/v0/destinations/redis/transform.js @@ -58,13 +58,32 @@ const process = (event) => { throw new InstrumentationError('Blank userId passed in identify event'); } - const { prefix } = destination.Config; + const { prefix, shouldSendDataAsJSON } = destination.Config; const destinationId = destination.ID; const keyPrefix = isEmpty(prefix) ? '' : `${prefix.trim()}:`; if (isSubEventTypeProfiles(message)) { const { workspaceId } = metadata; - return transformSubEventTypeProfiles(message, workspaceId, destinationId); + if (!shouldSendDataAsJSON) { + return transformSubEventTypeProfiles(message, workspaceId, destinationId); + } + // JSON.SET . + return { + key: `${workspaceId}:${destinationId}:${message.context.sources.profiles_entity}:${message.context.sources.profiles_id_type}:${message.userId}`, + value: { + [message.context.sources.profiles_model]: message.traits, + }, + }; + } + + // Option-2 + if (shouldSendDataAsJSON) { + // If redis should store information as JSON type + // JSON.SET . + return { + key: `${keyPrefix}user:${lodash.toString(message.userId)}`, + value: message.traits || message.context.traits, + }; } const hmap = {