From 711143687c9f065d8266363b424a7e1d7f7a768e Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Fri, 20 Sep 2024 16:13:13 +0300 Subject: [PATCH] Initial testing --- go.mod | 2 +- redis.go | 2 +- redis_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index bd13d745..c1d9037a 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. Please use version 9.6.0 instead. v9.5.4 // This version was accidentally released. Please use version 9.6.0 instead. + v9.5.3 // This version was accidentally released. Please use version 9.6.0 instead. ) diff --git a/redis.go b/redis.go index c8b50080..9d604928 100644 --- a/redis.go +++ b/redis.go @@ -431,7 +431,7 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool return false, err } } - + panic(cmd.firstKeyPos()) retryTimeout := uint32(0) if err := c.withConn(ctx, func(ctx context.Context, cn *pool.Conn) error { if err := cn.WithWriter(c.context(ctx), c.opt.WriteTimeout, func(wr *proto.Writer) error { diff --git a/redis_test.go b/redis_test.go index ef212545..e0fb026e 100644 --- a/redis_test.go +++ b/redis_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net" + "strconv" "testing" "time" @@ -633,3 +634,55 @@ var _ = Describe("Hook with MinIdleConns", func() { })) }) }) + +var _ = Describe("Command Name", func() { + var client *redis.Client + + BeforeEach(func() { + client = redis.NewClient(redisOptions()) + Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + err := client.Close() + Expect(err).NotTo(HaveOccurred()) + }) + + It("should return key name", func() { + mSet := client.MSet(ctx, "key1", "hello1", "key2", "hello2") + Expect(mSet.Err()).NotTo(HaveOccurred()) + Expect(mSet.Val()).To(Equal("OK")) + Expect(mSet.Args()).To(Equal([]string{"MSET", "key1", "hello1", "key2", "hello2"})) + + mGet := client.MGet(ctx, "key1", "key2", "_") + Expect(mGet.Err()).NotTo(HaveOccurred()) + Expect(mGet.Val()).To(Equal([]interface{}{"hello1", "hello2", nil})) + + // MSet struct + type set struct { + Set1 string `redis:"set1"` + Set2 int16 `redis:"set2"` + Set3 time.Duration `redis:"set3"` + Set4 interface{} `redis:"set4"` + Set5 map[string]interface{} `redis:"-"` + } + mSet = client.MSet(ctx, &set{ + Set1: "val1", + Set2: 1024, + Set3: 2 * time.Millisecond, + Set4: nil, + Set5: map[string]interface{}{"k1": 1}, + }) + Expect(mSet.Err()).NotTo(HaveOccurred()) + Expect(mSet.Val()).To(Equal("OK")) + + mGet = client.MGet(ctx, "set1", "set2", "set3", "set4") + Expect(mGet.Err()).NotTo(HaveOccurred()) + Expect(mGet.Val()).To(Equal([]interface{}{ + "val1", + "1024", + strconv.Itoa(int(2 * time.Millisecond.Nanoseconds())), + "", + })) + }) +})