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.
This commit is contained in:
parent
279b4a1464
commit
e9aba28932
32
src/t_set.c
32
src/t_set.c
@ -895,21 +895,21 @@ void sinterGenericCommand(client *c, robj **setkeys,
|
|||||||
if (dstkey) {
|
if (dstkey) {
|
||||||
/* Store the resulting set into the target, if the intersection
|
/* Store the resulting set into the target, if the intersection
|
||||||
* is not an empty set. */
|
* is not an empty set. */
|
||||||
int deleted = dbDelete(c->db,dstkey);
|
|
||||||
if (setTypeSize(dstset) > 0) {
|
if (setTypeSize(dstset) > 0) {
|
||||||
dbAdd(c->db,dstkey,dstset);
|
setKey(c,c->db,dstkey,dstset);
|
||||||
addReplyLongLong(c,setTypeSize(dstset));
|
addReplyLongLong(c,setTypeSize(dstset));
|
||||||
notifyKeyspaceEvent(NOTIFY_SET,"sinterstore",
|
notifyKeyspaceEvent(NOTIFY_SET,"sinterstore",
|
||||||
dstkey,c->db->id);
|
dstkey,c->db->id);
|
||||||
|
server.dirty++;
|
||||||
} else {
|
} else {
|
||||||
decrRefCount(dstset);
|
|
||||||
addReply(c,shared.czero);
|
addReply(c,shared.czero);
|
||||||
if (deleted)
|
if (dbDelete(c->db,dstkey)) {
|
||||||
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
|
server.dirty++;
|
||||||
dstkey,c->db->id);
|
signalModifiedKey(c,c->db,dstkey);
|
||||||
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
signalModifiedKey(c,c->db,dstkey);
|
decrRefCount(dstset);
|
||||||
server.dirty++;
|
|
||||||
} else {
|
} else {
|
||||||
setDeferredSetLen(c,replylen,cardinality);
|
setDeferredSetLen(c,replylen,cardinality);
|
||||||
}
|
}
|
||||||
@ -1069,22 +1069,22 @@ void sunionDiffGenericCommand(client *c, robj **setkeys, int setnum,
|
|||||||
} else {
|
} else {
|
||||||
/* If we have a target key where to store the resulting set
|
/* If we have a target key where to store the resulting set
|
||||||
* create this key with the result set inside */
|
* create this key with the result set inside */
|
||||||
int deleted = dbDelete(c->db,dstkey);
|
|
||||||
if (setTypeSize(dstset) > 0) {
|
if (setTypeSize(dstset) > 0) {
|
||||||
dbAdd(c->db,dstkey,dstset);
|
setKey(c,c->db,dstkey,dstset);
|
||||||
addReplyLongLong(c,setTypeSize(dstset));
|
addReplyLongLong(c,setTypeSize(dstset));
|
||||||
notifyKeyspaceEvent(NOTIFY_SET,
|
notifyKeyspaceEvent(NOTIFY_SET,
|
||||||
op == SET_OP_UNION ? "sunionstore" : "sdiffstore",
|
op == SET_OP_UNION ? "sunionstore" : "sdiffstore",
|
||||||
dstkey,c->db->id);
|
dstkey,c->db->id);
|
||||||
|
server.dirty++;
|
||||||
} else {
|
} else {
|
||||||
decrRefCount(dstset);
|
|
||||||
addReply(c,shared.czero);
|
addReply(c,shared.czero);
|
||||||
if (deleted)
|
if (dbDelete(c->db,dstkey)) {
|
||||||
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
|
server.dirty++;
|
||||||
dstkey,c->db->id);
|
signalModifiedKey(c,c->db,dstkey);
|
||||||
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
signalModifiedKey(c,c->db,dstkey);
|
decrRefCount(dstset);
|
||||||
server.dirty++;
|
|
||||||
}
|
}
|
||||||
zfree(sets);
|
zfree(sets);
|
||||||
}
|
}
|
||||||
|
10
src/t_zset.c
10
src/t_zset.c
@ -2184,7 +2184,6 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
|
|||||||
robj *dstobj;
|
robj *dstobj;
|
||||||
zset *dstzset;
|
zset *dstzset;
|
||||||
zskiplistNode *znode;
|
zskiplistNode *znode;
|
||||||
int touched = 0;
|
|
||||||
|
|
||||||
/* expect setnum input keys to be given */
|
/* expect setnum input keys to be given */
|
||||||
if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != C_OK))
|
if ((getLongFromObjectOrReply(c, c->argv[2], &setnum, NULL) != C_OK))
|
||||||
@ -2377,26 +2376,23 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
|
|||||||
serverPanic("Unknown operator");
|
serverPanic("Unknown operator");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbDelete(c->db,dstkey))
|
|
||||||
touched = 1;
|
|
||||||
if (dstzset->zsl->length) {
|
if (dstzset->zsl->length) {
|
||||||
zsetConvertToZiplistIfNeeded(dstobj,maxelelen);
|
zsetConvertToZiplistIfNeeded(dstobj,maxelelen);
|
||||||
dbAdd(c->db,dstkey,dstobj);
|
setKey(c,c->db,dstkey,dstobj);
|
||||||
addReplyLongLong(c,zsetLength(dstobj));
|
addReplyLongLong(c,zsetLength(dstobj));
|
||||||
signalModifiedKey(c,c->db,dstkey);
|
|
||||||
notifyKeyspaceEvent(NOTIFY_ZSET,
|
notifyKeyspaceEvent(NOTIFY_ZSET,
|
||||||
(op == SET_OP_UNION) ? "zunionstore" : "zinterstore",
|
(op == SET_OP_UNION) ? "zunionstore" : "zinterstore",
|
||||||
dstkey,c->db->id);
|
dstkey,c->db->id);
|
||||||
server.dirty++;
|
server.dirty++;
|
||||||
} else {
|
} else {
|
||||||
decrRefCount(dstobj);
|
|
||||||
addReply(c,shared.czero);
|
addReply(c,shared.czero);
|
||||||
if (touched) {
|
if (dbDelete(c->db,dstkey)) {
|
||||||
signalModifiedKey(c,c->db,dstkey);
|
signalModifiedKey(c,c->db,dstkey);
|
||||||
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
|
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
|
||||||
server.dirty++;
|
server.dirty++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
decrRefCount(dstobj);
|
||||||
zfree(src);
|
zfree(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user