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

[Feature request] HSet struct with pointer #2745

Closed
numberinho opened this issue Oct 6, 2023 Discussed in #2744 · 2 comments · Fixed by #2753
Closed

[Feature request] HSet struct with pointer #2745

numberinho opened this issue Oct 6, 2023 Discussed in #2744 · 2 comments · Fixed by #2753

Comments

@numberinho
Copy link

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!

@tzq0301
Copy link
Contributor

tzq0301 commented Oct 13, 2023

I create PR #2753 to fix it.

@tzq0301
Copy link
Contributor

tzq0301 commented Oct 19, 2023

@vmihailenco @ofekshenawa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants