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

[internal review] Go: implement standalone custom command #152

Conversation

aaron-congo
Copy link

@aaron-congo aaron-congo commented Mar 21, 2024

Note:

  • the Rust code should essentially be ignored since it is not final and will be polished up in a separate review
  • this is only for internal review of the Go code, I won't open a PR upstream until the finalized Rust code has been merged upstream in a separate PR

@aaron-congo aaron-congo changed the title Go: implement standalone command [internal review] Go: implement standalone command Mar 21, 2024
@aaron-congo aaron-congo changed the title [internal review] Go: implement standalone command [internal review] Go: implement standalone custom command Mar 21, 2024
Copy link

@acarbonetto acarbonetto left a comment

Choose a reason for hiding this comment

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

We can approve once we have lib.rs content.

go/api/commands.go Outdated Show resolved Hide resolved
go/api/base_client.go Outdated Show resolved Hide resolved
go/api/base_client.go Outdated Show resolved Hide resolved
//
// For example, to return a list of all pub/sub clients:
//
// client.CustomCommand([]string{"CLIENT", "LIST","TYPE", "PUBSUB"})

Choose a reason for hiding this comment

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

can we add a response to this example? what do we do with the returned payload/error?

Copy link
Author

@aaron-congo aaron-congo Mar 21, 2024

Choose a reason for hiding this comment

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

The other clients use this same example and similarly do not do anything with the response. Let me know if you want me to add one here anyways though. What should I do with the response? Just print it like this? Or should I show that it needs to be casted from interface{} to string if used for anything other than Printf (which accepts interface{} parameters)

result, err := client.CustomCommand([]string{"CLIENT", "LIST","TYPE", "PUBSUB"})
if err != nil {
    log.Fatal("error executing command: ", err)
}

fmt.Printf("result: %s", result)

Close()
}

type payload struct {

Choose a reason for hiding this comment

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

  1. capitalize
  2. which payload? response? connection? command? consider renaming
  3. add a doc

// TODO: call lib.rs function to free response
response := C.GoString(cResponse)
resultChannel := *(*chan payload)(channelPtr)
resultChannel <- payload{value: response, error: nil}

Choose a reason for hiding this comment

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

is it sync or async operation?

resultChannel := make(chan payload)
resultChannelPtr := uintptr(unsafe.Pointer(&resultChannel))

C.command(client.coreClient, C.uintptr_t(resultChannelPtr), requestType, C.uintptr_t(len(args)), &cArgs[0])

Choose a reason for hiding this comment

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

You changed callback singature to take channel pointer as void *. Should be here second argument be void * too?

@@ -20,3 +22,18 @@ func NewRedisClient(config *RedisClientConfiguration) (*RedisClient, error) {

return &RedisClient{client}, nil
}

// CustomCommand executes a single command, specified by args, without checking inputs. Every part of the command, including

Choose a reason for hiding this comment

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

Consider creating a list of interfaces as we did in java client.
Is it possible in go to split doc and implementation into different files?

//
// client.CustomCommand([]string{"CLIENT", "LIST","TYPE", "PUBSUB"})
func (client *RedisClient) CustomCommand(args []string) (interface{}, error) {
return client.executeCommand(C.CustomCommand, args)

Choose a reason for hiding this comment

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

add non-null and non-empty check for args

* Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0
*/
#![deny(unsafe_op_in_unsafe_fn)]
// TODO: uncomment

Choose a reason for hiding this comment

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

why commmented out?

) -> Result<Vec<String>, Utf8Error> {
from_raw_parts(data, len)
.iter()
.map(|arg| CStr::from_ptr(*arg).to_str().map(ToString::to_string))

Choose a reason for hiding this comment

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

add unsafe {}

use std::slice::from_raw_parts;
use std::str::Utf8Error;

pub unsafe fn convert_double_pointer_to_vec(

Choose a reason for hiding this comment

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

add docstring with # Safety section or remove unsafe
Also, should not be pub I think

cmd
}

use std::slice::from_raw_parts;

Choose a reason for hiding this comment

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

move to top

}

#[no_mangle]
pub unsafe extern "C" fn command(

Choose a reason for hiding this comment

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

add docstring with # Safety section

@aaron-congo
Copy link
Author

Closing as this is superseded by another PR upstream (valkey-io#1937)

@aaron-congo aaron-congo deleted the go/dev_acongo_standalone_command branch July 17, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants