Skip to content

Commit

Permalink
feat: add json-data type support in redis
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Sankeerth <[email protected]>
  • Loading branch information
Sai Sankeerth committed May 2, 2024
1 parent 7b1d11b commit db3205d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/v0/destinations/redis/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key> . <value>
return {

Check warning on line 71 in src/v0/destinations/redis/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transform.js#L71

Added line #L71 was not covered by tests
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 <key> . <value>
return {

Check warning on line 83 in src/v0/destinations/redis/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transform.js#L83

Added line #L83 was not covered by tests
key: `${keyPrefix}user:${lodash.toString(message.userId)}`,
value: message.traits || message.context.traits,

Check warning on line 85 in src/v0/destinations/redis/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/redis/transform.js#L85

Added line #L85 was not covered by tests
};
}

const hmap = {
Expand Down

0 comments on commit db3205d

Please sign in to comment.