Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Implement Bitfield and Bitfield ReadOnly commands #2999

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

niharikabhavaraju
Copy link
Collaborator

Go: Implement Bitfield and Bitfield ReadOnly commands

@niharikabhavaraju niharikabhavaraju requested a review from a team as a code owner January 23, 2025 18:41
@niharikabhavaraju niharikabhavaraju self-assigned this Jan 23, 2025
@niharikabhavaraju niharikabhavaraju added the go golang wrapper label Jan 23, 2025
return &BitFieldOptions{}
}

// AddGet adds a GET subcommand
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need docs for parameters?

return opts
}

func (opts *BitFieldOptions) ToArgs() []string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably return a tuple to align with others, even when error is always nil for now

Suggested change
func (opts *BitFieldOptions) ToArgs() []string {
func (opts *BitFieldOptions) ToArgs() ([]string, error) {

// fmt.Println(result) // Output: [7 13]
//
// [valkey.io]: https://valkey.io/commands/bitfield/
func (client *baseClient) BitField(key string, options *options.BitFieldOptions) ([]int64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With *options (pointer) a user can pass nil, but API is not designed to support this I think.

Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative variant is

Suggested change
func (client *baseClient) BitField(key string, options *options.BitFieldOptions) ([]int64, error) {
func (client *baseClient) BitField(key string, subcommands []BitFieldSubcommand) ([]int64, error) {

where

type BitFieldSubcommand interface {
	ToArgs() ([]string, error)
}

And you can share implementations for BitField and BitFieldRO

I did similar thing for ZRange

@@ -321,6 +321,29 @@ func handleIntArrayResponse(response *C.struct_CommandResponse) ([]int64, error)
return slice, nil
}

func handleIntOrNilArrayResponse(response *C.struct_CommandResponse) ([]int64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have https://github.com/niharikabhavaraju/valkey-glide/blob/34bd8722ad34a0ba7b37407a5752c8851feee9ce/go/api/response_handlers.go#L305

Or you want nillable ints there?

Suggested change
func handleIntOrNilArrayResponse(response *C.struct_CommandResponse) ([]int64, error) {
func handleIntOrNilArrayResponse(response *C.struct_CommandResponse) ([]Result[int64], error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go golang wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants