| 505 | } |
| 506 | |
| 507 | func TestIncrBy(t *testing.T) { |
| 508 | server.Clear() |
| 509 | c, err := proto.Dial(server.Addr()) |
| 510 | ok(t, err) |
| 511 | defer c.Close() |
| 512 | s := server.Direct() |
| 513 | |
| 514 | // Existing key |
| 515 | { |
| 516 | s.Set("foo", "12") |
| 517 | mustDo(t, c, |
| 518 | "INCRBY", "foo", "400", |
| 519 | proto.Int(412), |
| 520 | ) |
| 521 | s.CheckGet(t, "foo", "412") |
| 522 | } |
| 523 | |
| 524 | // Existing key, not an integer |
| 525 | { |
| 526 | s.Set("foo", "noint") |
| 527 | mustDo(t, c, |
| 528 | "INCRBY", "foo", "400", |
| 529 | proto.Error(msgInvalidInt), |
| 530 | ) |
| 531 | } |
| 532 | |
| 533 | // New key |
| 534 | { |
| 535 | mustDo(t, c, |
| 536 | "INCRBY", "bar", "4000", |
| 537 | proto.Int(4000), |
| 538 | ) |
| 539 | s.CheckGet(t, "bar", "4000") |
| 540 | } |
| 541 | |
| 542 | // Wrong type of existing key |
| 543 | { |
| 544 | s.HSet("wrong", "aap", "noot") |
| 545 | mustDo(t, c, |
| 546 | "INCRBY", "wrong", "400", |
| 547 | proto.Error(msgWrongType), |
| 548 | ) |
| 549 | } |
| 550 | |
| 551 | // Amount not an integer |
| 552 | mustDo(t, c, |
| 553 | "INCRBY", "key", "noint", |
| 554 | proto.Error(msgInvalidInt), |
| 555 | ) |
| 556 | |
| 557 | // Wrong usage |
| 558 | { |
| 559 | mustDo(t, c, |
| 560 | "INCRBY", |
| 561 | proto.Error(errWrongNumber("incrby")), |
| 562 | ) |
| 563 | mustDo(t, c, |
| 564 | "INCRBY", "another", "new", "key", |