| 541 | } |
| 542 | |
| 543 | void msetGenericCommand(client *c, int nx) { |
| 544 | int j; |
| 545 | |
| 546 | if ((c->argc % 2) == 0) { |
| 547 | addReplyError(c,"wrong number of arguments for MSET"); |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | /* Handle the NX flag. The MSETNX semantic is to return zero and don't |
| 552 | * set anything if at least one key already exists. */ |
| 553 | if (nx) { |
| 554 | for (j = 1; j < c->argc; j += 2) { |
| 555 | if (lookupKeyWrite(c->db,c->argv[j]) != NULL) { |
| 556 | addReply(c, shared.czero); |
| 557 | return; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | for (j = 1; j < c->argc; j += 2) { |
| 563 | c->argv[j+1] = tryObjectEncoding(c->argv[j+1]); |
| 564 | setKey(c,c->db,c->argv[j],c->argv[j+1]); |
| 565 | notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[j],c->db->id); |
| 566 | } |
| 567 | server.dirty += (c->argc-1)/2; |
| 568 | addReply(c, nx ? shared.cone : shared.ok); |
| 569 | } |
| 570 | |
| 571 | void msetCommand(client *c) { |
| 572 | msetGenericCommand(c,0); |
no test coverage detected