redis/go-redis

Can't get UUID with Scan()

lordspinach opened this issue · 1 comments

Expected Behavior

Can use UUID type for storing structs in hash tables

Current Behavior

Got invalid UUID length: 16 error from (uuid *UUID) UnmarshalText

Possible Solution

Add encoding.BinaryUnmarshaler to switch case at /internal/hscan/structmap.go:107

Steps to Reproduce

  1. Create structure with UUID field
  2. Set it to hash table with HSet()
  3. Get it back with HGetAll()
  4. Try to write given map[string]string to structure with Scan()

Detailed Description

I am facing a problem related to hash tables. I want to store objects in it, so I use HSet. Then encoding.BinaryMarshaler is used to marshal the UUID, but when I try to get the object back using Scan(), encoding.TextUnmarshaler is used instead of encoding.BinaryUnmarshaler to unmarshal it.
This is a incorrect use of these interfaces. As it is written in the description of these interfaces

UnmarshalBinary must be able to decode the form generated by MarshalBinary

And

UnmarshalText must be able to decode the form generated by MarshalText

They are not interchangeable and Binary should be used with Binary and Text with Text

Can I contribute to this by adding support for encoding.BinaryUnmarshaler in the Scan function?