Skip to content

Commit ad81691

Browse files
frankxjkuangofekshenawa
authored andcommitted
fix: Fix panic caused when arg is nil (redis#3353)
1 parent a79679d commit ad81691

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func appendArg(dst []interface{}, arg interface{}) []interface{} {
8181
return dst
8282
case time.Time, time.Duration, encoding.BinaryMarshaler, net.IP:
8383
return append(dst, arg)
84+
case nil:
85+
return dst
8486
default:
8587
// scan struct field
8688
v := reflect.ValueOf(arg)

commands_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7226,6 +7226,17 @@ var _ = Describe("Commands", func() {
72267226
Expect(err).NotTo(HaveOccurred())
72277227
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72287228
})
7229+
7230+
It("returns empty values when args are nil", func() {
7231+
vals, err := client.Eval(
7232+
ctx,
7233+
"return {ARGV[1]}",
7234+
[]string{},
7235+
nil,
7236+
).Result()
7237+
Expect(err).NotTo(HaveOccurred())
7238+
Expect(vals).To(BeEmpty())
7239+
})
72297240
})
72307241

72317242
Describe("EvalRO", func() {
@@ -7249,6 +7260,17 @@ var _ = Describe("Commands", func() {
72497260
Expect(err).NotTo(HaveOccurred())
72507261
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72517262
})
7263+
7264+
It("returns empty values when args are nil", func() {
7265+
vals, err := client.EvalRO(
7266+
ctx,
7267+
"return {ARGV[1]}",
7268+
[]string{},
7269+
nil,
7270+
).Result()
7271+
Expect(err).NotTo(HaveOccurred())
7272+
Expect(vals).To(BeEmpty())
7273+
})
72527274
})
72537275

72547276
Describe("Functions", func() {

0 commit comments

Comments
 (0)