Go: Implement PfMerge command#3082
Conversation
Signed-off-by: Niharika Bhavaraju <nbhavaraju@google.com>
| // | ||
| // [valkey.io]: https://valkey.io/commands/pfmerge/ | ||
| func (client *baseClient) PfMerge(destination string, sourceKeys []string) (string, error) { | ||
| result, err := client.executeCommand(C.PfMerge, append([]string{destination}, sourceKeys...)) |
There was a problem hiding this comment.
Can we check if at-least one sourceKey is as PFMerge require at least one source key and this would lead to anyhow failure and will waste one network call, we can use something like this :-
if len(sourceKeys) == 0 {
return "", errors.New("at least one source key is required for PfMerge")
}
There was a problem hiding this comment.
No need, we don't do this in other commands/clients
There was a problem hiding this comment.
But adding this check will make the execution of command more efficient isn't it, and if other clients have not implemented such behavior, it seems a miss because anyhow the execution of command is going to fail.
There was a problem hiding this comment.
@omangesg , I checked in valkey cli , the PFMERGE command with only a destination key and no source keys, will return "OK" as the response.
The command doesn't fail or produce an error, it creates the destination key as an empty HyperLogLog if it doesn't exist yet and returns "OK"

go/api/base_client.go
Outdated
| // Note: | ||
| // | ||
| // In cluster mode, if keys in `keyValueMap` map to different hash slots, the command | ||
| // will be split across these slots and executed separately for each. This means the command | ||
| // is atomic only at the slot level. If one or more slot-specific requests fail, the entire | ||
| // call will return the first encountered error, even though some requests may have succeeded | ||
| // while others did not. If this behavior impacts your application logic, consider splitting | ||
| // the request into sub-requests per slot to ensure atomicity. |
There was a problem hiding this comment.
There should be another cross-slot notice. If keys mapped to different slots, command fails.
Signed-off-by: Niharika Bhavaraju <nbhavaraju@google.com>
Yury-Fridlyand
left a comment
There was a problem hiding this comment.
Please update command example to match new example template (see developer doc and/or other commands)
Add a changelog entry
Signed-off-by: Niharika Bhavaraju <nbhavaraju@google.com>
Signed-off-by: Niharika Bhavaraju <nbhavaraju@google.com>
Go: Implement PfMerge command