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