Skip to content

Conversation

@wjdqhry
Copy link
Contributor

@wjdqhry wjdqhry commented Dec 17, 2021

Each time, struct had to be converted to map and put it in.
So I thought it would be better to embed it inside the function.

@wjdqhry wjdqhry changed the title feat: enable struct on HSet Allow struct on HSet Dec 17, 2021
@wjdqhry wjdqhry force-pushed the feature/struct-to-hashset branch from 884fc70 to 4ce9046 Compare December 22, 2021 05:26
@YuriPuck
Copy link

I want to use this feature

@vmihailenco vmihailenco force-pushed the master branch 3 times, most recently from 7d6f91b to 6fd61e8 Compare February 22, 2022 13:29
@monkey92t
Copy link
Collaborator

Should we use the "json" tag? I feel like it's better handled by the person who needs it.

func structToMap() {
    ....
}

client.Hset(ctx, "key", structToMap(items))

@wjdqhry
Copy link
Contributor Author

wjdqhry commented Mar 18, 2022

Should we use the "json" tag? I feel like it's better handled by the person who needs it.

func structToMap() {
    ....
}

client.Hset(ctx, "key", structToMap(items))

Thank you for your reply.

I felt that the experience of using the library was reduced because the person who wanted it had to make it from the outside, and I thought it would be ideal to solve it internally.

It doesn't have to be a "json" tag, but I think we need a tag for our hash keys.

@monkey92t
Copy link
Collaborator

We should think more, like tag="" or tag="-", or for types like:

type Demo struct {
    Pers []int
    Ptr *struct
    Map map[string]*struct
    ...
}

@wjdqhry
Copy link
Contributor Author

wjdqhry commented Apr 28, 2022

I modified the tag name. The example has also been modified.

But if you don't think it's necessary, you can close the PR!

@michaelfeinbier
Copy link

I was wondering why this does not exist yet.

Thanks for the code - I guess you should maybe use the tag redis as it is already used for the other way round if you scan a HGetAll to a struct

@wjdqhry
Copy link
Contributor Author

wjdqhry commented Jan 19, 2023

Sorry i'm just too late..
Thank you for your feedback!

I accepted your feedback and I just changed serialize key "key" to "redis"

@monkey92t
Copy link
Collaborator

I added support for structure types in the appendArgs function, so that MSet, MSetNX functions can also benefit.

I added the description of using the struct type in the API comments, and added the test function.

We should note that for complex field types of structures, the encoding.BinaryMarshaler interface should be implemented.

Synchronized with v9.

Signed-off-by: monkey92t <[email protected]>
@monkey92t monkey92t merged commit 31f6ce0 into redis:master Jan 19, 2023
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 this pull request may close these issues.

4 participants