Adds new ValkeyModule_CallArgv API function #3122
Open
+519
−191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds a new module API function called
ValkeyModule_CallArgvto allow modules to call server commands. This function is a low-latency version ofValkeyModule_Call, which can be used in latency sensitive modules like the Lua module.The signature of the new function is the following:
This new function differs from the already existing
ValkeyModule_Callin the following items:VM_CallArgvalready receives the arguments arrayargvthat can be passed directly to the client object, avoiding the parsing of the format string of (VM_Call), and also the allocation of a newargvarray. The caller ofVM_CallArgvhas the owership ofargvand is responsible for its lifetime.flagsare also passed directly inVM_CallArgv, which avoids the flag parsing done in `VM_Call.ValkeyModuleCallRawReplyobject, which in fact is just an alias for the fake client that executed the command. This object allows theVM_CallArgvcaller to access the command result encoded in RESP without any memory allocation most of the times.There are four additional API functions to work with the
ValkeyModuleCallRawReplyobject.The
VM_CallRawReplyToCallReplyfunction, converts a raw reply object into a reply object. When using this function, theraw_replyobject cannot be used anymore, and there is no need to callVM_CallRawReplyReleaseon it.The
VM_CallRawReplyIsBlockedchecks whether theraw_replycorresponds to a blocking client reply. When this function returnstrue, then the user should convert the raw reply in aValkeyModuleCallReplyobject, which will correspond to a promise reply.The
VM_CallRawReplyBufferwill return a C string buffer with the RESP result of the command. In most cases, this buffer points directly to the client reply buffer, and in this case theis_owneris set to0. Otherwise, the caller becomes the owner of the buffer and is responsible for freeing it.The
VM_CallRawReplyReleasereleases all resources associated with the raw reply object. This is when the faked client that performed the call returns to the fake client cache.