go-redis
go-redis copied to clipboard
redis: can't marshal map[string]main.student (implement encoding.BinaryMarshaler)
Issue tracker is used for reporting bugs and discussing new features. Please use stackoverflow for supporting issues.
Expected Behavior
I hope HSet can support store map[string]struct.
Current Behavior
redis: can't marshal map[string]main.student (implement encoding.BinaryMarshaler)
Steps to Reproduce
type student struct { Name string Age int }
func (s student) MarshalBinary() (data []byte, err error) { data, err = json.Marshal(&s) return }
func main() { rdb := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "2000.redis", }) m := make(map[string]student) m["1"] = student{ "sxy", 18, } m["2"] = student{ "szw", 0, } ctx := context.Background() cmd := rdb.HSet(ctx, "student", m) fmt.Println(cmd.Err()) x := rdb.HGet(ctx, "student", "1") fmt.Println(x) }
Some mods found in here: https://github.com/RedisJSON/RedisJSON
go-rejson Go MIT rejonson Go Apache-2.0 rueidis Go Apache-2.0
This issue is marked stale. It will be closed in 30 days if it is not updated.