go-redis icon indicating copy to clipboard operation
go-redis copied to clipboard

redis: can't marshal map[string]main.student (implement encoding.BinaryMarshaler)

Open capyun opened this issue 2 years ago • 1 comments

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) }

capyun avatar May 12 '22 13:05 capyun

Some mods found in here: https://github.com/RedisJSON/RedisJSON

go-rejson Go MIT rejonson Go Apache-2.0 rueidis Go Apache-2.0

cncap avatar May 17 '22 16:05 cncap

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Sep 22 '23 00:09 github-actions[bot]