|
6 | 6 | "errors" |
7 | 7 | "fmt" |
8 | 8 | "net" |
| 9 | + "strconv" |
9 | 10 | "testing" |
10 | 11 | "time" |
11 | 12 |
|
@@ -633,3 +634,55 @@ var _ = Describe("Hook with MinIdleConns", func() { |
633 | 634 | })) |
634 | 635 | }) |
635 | 636 | }) |
| 637 | + |
| 638 | +var _ = Describe("Command Name", func() { |
| 639 | + var client *redis.Client |
| 640 | + |
| 641 | + BeforeEach(func() { |
| 642 | + client = redis.NewClient(redisOptions()) |
| 643 | + Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) |
| 644 | + }) |
| 645 | + |
| 646 | + AfterEach(func() { |
| 647 | + err := client.Close() |
| 648 | + Expect(err).NotTo(HaveOccurred()) |
| 649 | + }) |
| 650 | + |
| 651 | + It("should return key name", func() { |
| 652 | + mSet := client.MSet(ctx, "key1", "hello1", "key2", "hello2") |
| 653 | + Expect(mSet.Err()).NotTo(HaveOccurred()) |
| 654 | + Expect(mSet.Val()).To(Equal("OK")) |
| 655 | + Expect(mSet.Args()).To(Equal([]string{"MSET", "key1", "hello1", "key2", "hello2"})) |
| 656 | + |
| 657 | + mGet := client.MGet(ctx, "key1", "key2", "_") |
| 658 | + Expect(mGet.Err()).NotTo(HaveOccurred()) |
| 659 | + Expect(mGet.Val()).To(Equal([]interface{}{"hello1", "hello2", nil})) |
| 660 | + |
| 661 | + // MSet struct |
| 662 | + type set struct { |
| 663 | + Set1 string `redis:"set1"` |
| 664 | + Set2 int16 `redis:"set2"` |
| 665 | + Set3 time.Duration `redis:"set3"` |
| 666 | + Set4 interface{} `redis:"set4"` |
| 667 | + Set5 map[string]interface{} `redis:"-"` |
| 668 | + } |
| 669 | + mSet = client.MSet(ctx, &set{ |
| 670 | + Set1: "val1", |
| 671 | + Set2: 1024, |
| 672 | + Set3: 2 * time.Millisecond, |
| 673 | + Set4: nil, |
| 674 | + Set5: map[string]interface{}{"k1": 1}, |
| 675 | + }) |
| 676 | + Expect(mSet.Err()).NotTo(HaveOccurred()) |
| 677 | + Expect(mSet.Val()).To(Equal("OK")) |
| 678 | + |
| 679 | + mGet = client.MGet(ctx, "set1", "set2", "set3", "set4") |
| 680 | + Expect(mGet.Err()).NotTo(HaveOccurred()) |
| 681 | + Expect(mGet.Val()).To(Equal([]interface{}{ |
| 682 | + "val1", |
| 683 | + "1024", |
| 684 | + strconv.Itoa(int(2 * time.Millisecond.Nanoseconds())), |
| 685 | + "", |
| 686 | + })) |
| 687 | + }) |
| 688 | +}) |
0 commit comments