Skip to content

Should HSetEX arguments be interface{}? #3517

@natenho

Description

@natenho

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions