From 2b3ceff12271eb49df9e95a3e90c3aa3c1045736 Mon Sep 17 00:00:00 2001 From: Qu Chen Date: Fri, 3 Jan 2025 17:36:48 -0800 Subject: [PATCH] Avoid using low level dictAddRaw() and dictSetKey() for ZUNION operation. --- src/t_zset.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/t_zset.c b/src/t_zset.c index e8c5a369b7..2c843137a6 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -2793,7 +2793,7 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in if (isnan(score)) score = 0; /* Search for this element in the accumulating dictionary. */ - de = dictAddRaw(dstzset->dict, zuiSdsFromValue(&zval), &existing); + existing = dictFind(dstzset->dict, zuiSdsFromValue(&zval)); /* If we don't have it, we need to create a new entry. */ if (!existing) { tmp = zuiNewSdsFromValue(&zval); @@ -2802,8 +2802,8 @@ void zunionInterDiffGenericCommand(client *c, robj *dstkey, int numkeysIndex, in * at the end. */ totelelen += sdslen(tmp); if (sdslen(tmp) > maxelelen) maxelelen = sdslen(tmp); - /* Update the element with its initial score. */ - dictSetKey(dstzset->dict, de, tmp); + /* Insert the element with its initial score. */ + de = dictAddRaw(dstzset->dict, tmp, NULL); dictSetDoubleVal(de, score); } else { /* Update the score with the score of the new instance