Skip to content

Commit 8a2dfe6

Browse files
author
Guo Hui
committed
fix:func isEmptyValue support time.Time
1 parent 7f8b5a8 commit 8a2dfe6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

commands.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ func isEmptyValue(v reflect.Value) bool {
153153
return v.Float() == 0
154154
case reflect.Interface, reflect.Pointer:
155155
return v.IsNil()
156+
case reflect.Struct:
157+
return v.IsZero()
156158
}
157159
return false
158160
}

commands_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,19 @@ var _ = Describe("Commands", func() {
25172517
"val2",
25182518
"val",
25192519
}))
2520+
2521+
type set2 struct {
2522+
Set1 string `redis:"set1"`
2523+
Set2 int `redis:"set2,omitempty"`
2524+
Set3 time.Duration `redis:"set3,omitempty"`
2525+
Set4 string `redis:"set4,omitempty"`
2526+
Set5 time.Time `redis:"set5,omitempty"`
2527+
}
2528+
hSet = client.HSet(ctx, "hash3", &set2{
2529+
Set1: "val",
2530+
})
2531+
Expect(hSet.Err()).NotTo(HaveOccurred())
2532+
Expect(hSet.Val()).To(Equal(int64(1)))
25202533
})
25212534

25222535
It("should HSetNX", func() {

0 commit comments

Comments
 (0)