@@ -444,13 +444,6 @@ redis.registerStreamTrigger(
444444 ' calculateStats' , // trigger name
445445 ' TRANSACTION_STREAM' , // Detects new data added to the stream
446446 function (client , data ) {
447- // data = JSON.stringify(
448- // data,
449- // (key, value) => (typeof value === "bigint" ? value.toString() : value) //id conversion
450- // );
451-
452- // data = JSON.parse(data);
453-
454447 var streamEntry = {};
455448 for (let i = 0 ; i < data .record ? .length ; i++ ) {
456449 streamEntry[data .record [i][0 ]] = data .record [i][1 ];
@@ -528,6 +521,13 @@ redis.registerStreamTrigger(
528521);
529522` ` `
530523
524+ In above ` calculateStats` function, we are listening to ` TRANSACTION_STREAM ` and updating different sales statistics like
525+
526+ - ` statsTotalPurchaseAmount` variable stores total purchase amount
527+ - ` statsProductPurchaseQtySet` is a sorted set which tracks trending products based on highest purchase quantity
528+ - ` statsCategoryPurchaseAmountSet` is a sorted set which tracks category wise purchase interest
529+ - ` statsBrandPurchaseAmountSet` is a sorted set which tracks largest brand purchases
530+
531531### Adding the function to Redis
532532
533533We can add functions to Redis using various methods:
@@ -609,7 +609,7 @@ A sample command to add details to the stream:
609609" XADD" " TRANSACTION_STREAM" " *" " action" " PAYMENT_PROCESSED" " userId" " USR_f0f00a86-7131" " orderDetails" " {'orderId':'bc438c5d-117e-41bd-97fa-943c03be0b1c','products':[],'paymentId':'clrrl8yp50007pf851m7f92u2'}" " transactionPipeline" " ['PAYMENT_PROCESSED']"
610610` ` `
611611
612- The ` calculateStats` function listens to ` TRANSACTION_STREAM ` stream and updates the sales statistics accordingly.
612+ The ` calculateStats` function listens to ` TRANSACTION_STREAM ` stream for ` PAYMENT_PROCESSED ` action and updates the sales statistics accordingly.
613613
614614Check different stats variable values in RedisInsight which were used in trigger function ` calculateStats` .
615615
0 commit comments