-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
This seems to be a memory saving opportunity, please let me know your thoughts.
The HSet receives interface{}
as values
HSet(ctx context.Context, key string, values ...interface{}) *IntCmd
But HSetEX and WithArgs variant receives string:
HSetEX(ctx context.Context, key string, fieldsAndValues ...string) *IntCmd
HSetEXWithArgs(ctx context.Context, key string, options *HSetEXOptions, fieldsAndValues ...string) *IntCmd
In case we are, for instance, passing a JSON []byte, we need to convert it to string, like the example below:
jsonTags, err := json.Marshal(tags)
c.HSetEX(ctx, "xxx", "tags", string(jsonTags))
And afaik, the string(xxxx) allocates a new string, which can be undesirable in hot path scenarios.
So maybe the optimal would be to also receive interface{}/any for these functions, as internally the pkg ensure low memory consumption by using unsafe pointers.