MCPcopy Create free account
hub / github.com/F-Stack/f-stack / smoveCommand

Function smoveCommand

app/redis-6.2.6/src/t_set.c:354–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352}
353
354void smoveCommand(client *c) {
355 robj *srcset, *dstset, *ele;
356 srcset = lookupKeyWrite(c->db,c->argv[1]);
357 dstset = lookupKeyWrite(c->db,c->argv[2]);
358 ele = c->argv[3];
359
360 /* If the source key does not exist return 0 */
361 if (srcset == NULL) {
362 addReply(c,shared.czero);
363 return;
364 }
365
366 /* If the source key has the wrong type, or the destination key
367 * is set and has the wrong type, return with an error. */
368 if (checkType(c,srcset,OBJ_SET) ||
369 checkType(c,dstset,OBJ_SET)) return;
370
371 /* If srcset and dstset are equal, SMOVE is a no-op */
372 if (srcset == dstset) {
373 addReply(c,setTypeIsMember(srcset,ele->ptr) ?
374 shared.cone : shared.czero);
375 return;
376 }
377
378 /* If the element cannot be removed from the src set, return 0. */
379 if (!setTypeRemove(srcset,ele->ptr)) {
380 addReply(c,shared.czero);
381 return;
382 }
383 notifyKeyspaceEvent(NOTIFY_SET,"srem",c->argv[1],c->db->id);
384
385 /* Remove the src set from the database when empty */
386 if (setTypeSize(srcset) == 0) {
387 dbDelete(c->db,c->argv[1]);
388 notifyKeyspaceEvent(NOTIFY_GENERIC,"del",c->argv[1],c->db->id);
389 }
390
391 /* Create the destination set when it doesn't exist */
392 if (!dstset) {
393 dstset = setTypeCreate(ele->ptr);
394 dbAdd(c->db,c->argv[2],dstset);
395 }
396
397 signalModifiedKey(c,c->db,c->argv[1]);
398 server.dirty++;
399
400 /* An extra key has changed when ele was successfully added to dstset */
401 if (setTypeAdd(dstset,ele->ptr)) {
402 server.dirty++;
403 signalModifiedKey(c,c->db,c->argv[2]);
404 notifyKeyspaceEvent(NOTIFY_SET,"sadd",c->argv[2],c->db->id);
405 }
406 addReply(c,shared.cone);
407}
408
409void sismemberCommand(client *c) {
410 robj *set;

Callers

nothing calls this directly

Calls 12

lookupKeyWriteFunction · 0.85
addReplyFunction · 0.85
checkTypeFunction · 0.85
setTypeIsMemberFunction · 0.85
setTypeRemoveFunction · 0.85
notifyKeyspaceEventFunction · 0.85
setTypeSizeFunction · 0.85
dbDeleteFunction · 0.85
setTypeCreateFunction · 0.85
dbAddFunction · 0.85
signalModifiedKeyFunction · 0.85
setTypeAddFunction · 0.85

Tested by

no test coverage detected