From b0dd2cabd6f8e339f324bf31ee5d1fe30f2c012d Mon Sep 17 00:00:00 2001 From: "sojung.kim" Date: Thu, 3 Oct 2024 20:18:54 +0900 Subject: [PATCH 1/2] feat: add encoding.BinaryUnmarshaler in Scan --- internal/hscan/structmap.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/hscan/structmap.go b/internal/hscan/structmap.go index 1a560e4a..408ce0e4 100644 --- a/internal/hscan/structmap.go +++ b/internal/hscan/structmap.go @@ -109,6 +109,8 @@ func (s StructValue) Scan(key string, value string) error { return scan.ScanRedis(value) case encoding.TextUnmarshaler: return scan.UnmarshalText(util.StringToBytes(value)) + case encoding.BinaryUnmarshaler: + return scan.UnmarshalBinary(util.StringToBytes(value)) } } From f97720d43f87e7e3fd949a77d9c9df5f4a5d306a Mon Sep 17 00:00:00 2001 From: "sojung.kim" Date: Wed, 23 Oct 2024 20:30:25 +0900 Subject: [PATCH 2/2] test: add unmarshal UUID test --- go.mod | 1 + go.sum | 2 ++ internal/hscan/hscan_test.go | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c1d9037a..56145a16 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/bsm/gomega v1.27.10 github.com/cespare/xxhash/v2 v2.2.0 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f + github.com/google/uuid v1.6.0 ) retract ( diff --git a/go.sum b/go.sum index 21b4f64e..3818527d 100644 --- a/go.sum +++ b/go.sum @@ -6,3 +6,5 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/internal/hscan/hscan_test.go b/internal/hscan/hscan_test.go index 6c9b3030..29951ec6 100644 --- a/internal/hscan/hscan_test.go +++ b/internal/hscan/hscan_test.go @@ -8,7 +8,7 @@ import ( . "github.com/bsm/ginkgo/v2" . "github.com/bsm/gomega" - + "github.com/google/uuid" "github.com/redis/go-redis/v9/internal/util" ) @@ -48,6 +48,10 @@ type TimeData struct { Time *TimeRFC3339Nano `redis:"login"` } +type UUIDData struct { + ID uuid.UUID `redis:"id"` +} + type i []interface{} func TestGinkgoSuite(t *testing.T) { @@ -217,4 +221,13 @@ var _ = Describe("Scan", func() { Expect(Scan(&tt, i{"time"}, i{now.Format(time.RFC3339Nano)})).NotTo(HaveOccurred()) Expect(now.Unix()).To(Equal(tt.Time.Unix())) }) + + It("should unmarshal UUID", func() { + var ud UUIDData + + testUUID := uuid.New() + + Expect(Scan(&ud, i{"id"}, i{testUUID.String()})).NotTo(HaveOccurred()) + Expect(ud.ID).To(Equal(testUUID)) + }) })