summaryrefslogtreecommitdiff
path: root/src/t_set.c
diff options
context:
space:
mode:
author杨博东 <bodong.ybd@alibaba-inc.com>2020-07-11 20:52:41 +0800
committerGitHub <noreply@github.com>2020-07-11 15:52:41 +0300
commite9aba28932c6a0450c14ecd984603d41f31e0f0d (patch)
tree242adc663e10d5816150013a607f0e8825eddc0f /src/t_set.c
parent279b4a14643f247365637da13439fcb407072a9d (diff)
downloadredis-e9aba28932c6a0450c14ecd984603d41f31e0f0d.tar.gz
STORE variants: SINTER,SUNION,SDIFF,ZUNION use setKey instead of dbDelete+dbAdd (#7489)
one of the differences (other than consistent code with SORT, GEORADIUS), is that the LFU of the old key is retained.
Diffstat (limited to 'src/t_set.c')
-rw-r--r--src/t_set.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/t_set.c b/src/t_set.c
index c2e73a6e6..75678f47c 100644
--- a/src/t_set.c
+++ b/src/t_set.c
@@ -895,21 +895,21 @@ void sinterGenericCommand(client *c, robj **setkeys,
if (dstkey) {
/* Store the resulting set into the target, if the intersection
* is not an empty set. */
- int deleted = dbDelete(c->db,dstkey);
if (setTypeSize(dstset) > 0) {
- dbAdd(c->db,dstkey,dstset);
+ setKey(c,c->db,dstkey,dstset);
addReplyLongLong(c,setTypeSize(dstset));
notifyKeyspaceEvent(NOTIFY_SET,"sinterstore",
dstkey,c->db->id);
+ server.dirty++;
} else {
- decrRefCount(dstset);
addReply(c,shared.czero);
- if (deleted)
- notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
- dstkey,c->db->id);
+ if (dbDelete(c->db,dstkey)) {
+ server.dirty++;
+ signalModifiedKey(c,c->db,dstkey);
+ notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
+ }
}
- signalModifiedKey(c,c->db,dstkey);
- server.dirty++;
+ decrRefCount(dstset);
} else {
setDeferredSetLen(c,replylen,cardinality);
}
@@ -1069,22 +1069,22 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum,
} else {
/* If we have a target key where to store the resulting set
* create this key with the result set inside */
- int deleted = dbDelete(c->db,dstkey);
if (setTypeSize(dstset) > 0) {
- dbAdd(c->db,dstkey,dstset);
+ setKey(c,c->db,dstkey,dstset);
addReplyLongLong(c,setTypeSize(dstset));
notifyKeyspaceEvent(NOTIFY_SET,
op == SET_OP_UNION ? "sunionstore" : "sdiffstore",
dstkey,c->db->id);
+ server.dirty++;
} else {
- decrRefCount(dstset);
addReply(c,shared.czero);
- if (deleted)
- notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
- dstkey,c->db->id);
+ if (dbDelete(c->db,dstkey)) {
+ server.dirty++;
+ signalModifiedKey(c,c->db,dstkey);
+ notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
+ }
}
- signalModifiedKey(c,c->db,dstkey);
- server.dirty++;
+ decrRefCount(dstset);
}
zfree(sets);
}