Skip to content

[Feature request] HSet struct with pointer #2745

Closed
@numberinho

Description

@numberinho

Discussed in #2744

Originally posted by numberinho October 6, 2023
I'm trying to HSet() structs with pointers.

Example:

cl := redis.NewClient(&redis.Options{
	Addr:     "localhost:6386",
	Password: "", // no password set
	DB:       0,  // use default DB
	PoolSize: 100,
})

type pointer struct {
	PtrInt *int    `redis:"ptrInt"`
	PtrStr *string `redis:"ptrStr"`
}

i := 1
s := "s"
p := pointer{&i, &s}

err := cl.HSet(context.Background(), "key", p).Err()
fmt.Println(err)

// redis: can't marshal *int (implement encoding.BinaryMarshaler)

How would you solve this? In my current application I have to store like 30 different structs, all having pointers to "simple data types" like *string and *int. The marshaling of them would be a super cool feature!

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions