Skip to content

Commit adb4798

Browse files
frankxjkuangndyakov
authored andcommitted
fix: Fix panic caused when arg is nil (#3353)
1 parent b203bfd commit adb4798

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

commands.go

+2
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

+22
Original file line numberDiff line numberDiff line change
@@ -7209,6 +7209,17 @@ var _ = Describe("Commands", func() {
72097209
Expect(err).NotTo(HaveOccurred())
72107210
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72117211
})
7212+
7213+
It("returns empty values when args are nil", func() {
7214+
vals, err := client.Eval(
7215+
ctx,
7216+
"return {ARGV[1]}",
7217+
[]string{},
7218+
nil,
7219+
).Result()
7220+
Expect(err).NotTo(HaveOccurred())
7221+
Expect(vals).To(BeEmpty())
7222+
})
72127223
})
72137224

72147225
Describe("EvalRO", func() {
@@ -7232,6 +7243,17 @@ var _ = Describe("Commands", func() {
72327243
Expect(err).NotTo(HaveOccurred())
72337244
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72347245
})
7246+
7247+
It("returns empty values when args are nil", func() {
7248+
vals, err := client.EvalRO(
7249+
ctx,
7250+
"return {ARGV[1]}",
7251+
[]string{},
7252+
nil,
7253+
).Result()
7254+
Expect(err).NotTo(HaveOccurred())
7255+
Expect(vals).To(BeEmpty())
7256+
})
72357257
})
72367258

72377259
Describe("Functions", func() {

0 commit comments

Comments
 (0)