Skip to content

Feature Request: Type Safe Args API #3570

@dragneelfps

Description

@dragneelfps

Currently, there are few commands which takes varargs(args ...interface{}) for additional arguments. Examples include BitFieldRO, SAdd.
We handle the args in several ways(non exhaustive list) -

  1. Have validation on the args array - BitFieldRO
  2. Let Redis handle it - no args(members) in SAdd will make redis throw an error

These commands make it harder for users to reason on what is acceptable and what is not. Users have to refer to Redis documentation to know what fields need to be passed and type of them.

I want to propose either updating these commands to take types args or creating new commands(to avoid breaking client usages on library upgrade).

For commands of type 1, below is my proposal -

func (c cmdable) BitFieldRO(ctx context.Context, key string, values []EncodingWithOffest) *IntSliceCmd { ... } type EncodingWithOffset struct { Encoding Encoding // we can use string or enums Offset int64 }

For commands of type 2, I would prefer if the commands can enforce obvious error scenarios such as no args passed in SAdd like below -

func (c cmdable) SAdd(ctx context.Context, key string, member interface{}, additionalMembers ...interface{}) *IntCmd { ... }

This is not a concrete proposal of how the type safe APIs will look like. I would like to discuss with you all on what's the best way to model them.
I am happy to contribute code if go-redis team is okay with this feature request.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions