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); } diff --git a/src/t_zset.c b/src/t_zset.c index 9c409cd96..16131ee85 100644 --- a/src/t_zset.c +++ b/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); }