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