From 5d7eaf8f5f0d01923d27e4e4d1f46006061bbba2 Mon Sep 17 00:00:00 2001 From: frankxjkuang Date: Sat, 19 Apr 2025 23:01:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9Bfix:=20Fix=20panic=20caused=20w?= =?UTF-8?q?hen=20arg=20is=20nil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands.go b/commands.go index 6321c15e2..01f1475d0 100644 --- a/commands.go +++ b/commands.go @@ -81,6 +81,8 @@ func appendArg(dst []interface{}, arg interface{}) []interface{} { return dst case time.Time, time.Duration, encoding.BinaryMarshaler, net.IP: return append(dst, arg) + case nil: + return dst default: // scan struct field v := reflect.ValueOf(arg) From 73b89968f2333ea58babef35b613fc550ccf7cc2 Mon Sep 17 00:00:00 2001 From: frankj Date: Wed, 23 Apr 2025 14:52:22 +0800 Subject: [PATCH 2/2] Update commands_test.go Test the case of adding the args parameter nil for Eval and EvalRO --- commands_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/commands_test.go b/commands_test.go index 55b957496..6a76756a9 100644 --- a/commands_test.go +++ b/commands_test.go @@ -7209,6 +7209,17 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"})) }) + + It("returns empty values when args are nil", func() { + vals, err := client.Eval( + ctx, + "return {ARGV[1]}", + []string{}, + nil, + ).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(vals).To(BeEmpty()) + }) }) Describe("EvalRO", func() { @@ -7232,6 +7243,17 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"})) }) + + It("returns empty values when args are nil", func() { + vals, err := client.EvalRO( + ctx, + "return {ARGV[1]}", + []string{}, + nil, + ).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(vals).To(BeEmpty()) + }) }) Describe("Functions", func() {