Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add encoding.BinaryUnmarshaler in Scan #3144

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/bsm/gomega v1.27.10
github.com/cespare/xxhash/v2 v2.3.0
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f
github.com/google/uuid v1.6.0
)

retract (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
github.com/cespare/xxhash/v2 v2.3.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=
15 changes: 14 additions & 1 deletion internal/hscan/hscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
})
})
2 changes: 2 additions & 0 deletions internal/hscan/structmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Loading