You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched previous discussions about supporting of map[string]any. It's excellent. However in many cases, hash is used with struct, like below in the example:
// Scan all fields into the model.
if err := rdb.HGetAll(ctx, "key").Scan(&model1); err != nil {
panic(err)
}
But where is the reverse? As we have a redis struct tag in the struct for reading from redis, why not to use it for writing as well? We may have a function like rdb.HSetAll(ctx, somestruct) though it's not a redis command. In order to avoid misunderstanding, we may have a different func name as well to denote it's extended function at client side.
If i have to store struct in redis, i firstly marshal it to json and then unmarshal json to map. In this case you have to be very carefull about consistence between the json tag and redis tag every time, which is bug prone and may cause performance decrease as well. If we have a function like the above, we don't have to care about the consistence between struct tags as the same redis tag is used for both writing and reading purpose.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I searched previous discussions about supporting of map[string]any. It's excellent. However in many cases, hash is used with struct, like below in the example:
But where is the reverse? As we have a redis struct tag in the struct for reading from redis, why not to use it for writing as well? We may have a function like
rdb.HSetAll(ctx, somestruct)
though it's not a redis command. In order to avoid misunderstanding, we may have a different func name as well to denote it's extended function at client side.If i have to store struct in redis, i firstly marshal it to json and then unmarshal json to map. In this case you have to be very carefull about consistence between the json tag and redis tag every time, which is bug prone and may cause performance decrease as well. If we have a function like the above, we don't have to care about the consistence between struct tags as the same
redis tag
is used for both writing and reading purpose.Beta Was this translation helpful? Give feedback.
All reactions