mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
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) {
|
||||
/* 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);
|
||||
}
|
||||
|
10
src/t_zset.c
10
src/t_zset.c
@ -2184,7 +2184,6 @@ void zunionInterGenericCommand(client *c, robj *dstkey, int op) {
|
||||
robj *dstobj;
|
||||
zset *dstzset;
|
||||
zskiplistNode *znode;
|
||||
int touched = 0;
|
||||
|
||||
/* expect setnum input keys to be given */
|
||||
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");
|
||||
}
|
||||
|
||||
if (dbDelete(c->db,dstkey))
|
||||
touched = 1;
|
||||
if (dstzset->zsl->length) {
|
||||
zsetConvertToZiplistIfNeeded(dstobj,maxelelen);
|
||||
dbAdd(c->db,dstkey,dstobj);
|
||||
setKey(c,c->db,dstkey,dstobj);
|
||||
addReplyLongLong(c,zsetLength(dstobj));
|
||||
signalModifiedKey(c,c->db,dstkey);
|
||||
notifyKeyspaceEvent(NOTIFY_ZSET,
|
||||
(op == SET_OP_UNION) ? "zunionstore" : "zinterstore",
|
||||
dstkey,c->db->id);
|
||||
server.dirty++;
|
||||
} else {
|
||||
decrRefCount(dstobj);
|
||||
addReply(c,shared.czero);
|
||||
if (touched) {
|
||||
if (dbDelete(c->db,dstkey)) {
|
||||
signalModifiedKey(c,c->db,dstkey);
|
||||
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",dstkey,c->db->id);
|
||||
server.dirty++;
|
||||
}
|
||||
}
|
||||
decrRefCount(dstobj);
|
||||
zfree(src);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user