-
Notifications
You must be signed in to change notification settings - Fork 53
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
Node: added FCALL and FCALL_RO commands #2011
Merged
yipin-chen
merged 3 commits into
valkey-io:main
from
Bit-Quill:node/integ_yipin_fcall_valkey-82
Jul 25, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { Buffer, BufferWriter, Reader, Writer } from "protobufjs"; | |
import { | ||
AggregationType, | ||
ExpireOptions, | ||
GeoUnit, | ||
InsertPosition, | ||
KeyWeight, | ||
RangeByIndex, | ||
|
@@ -34,10 +35,12 @@ import { | |
createExists, | ||
createExpire, | ||
createExpireAt, | ||
createFCall, | ||
createFCallReadOnly, | ||
createGeoAdd, | ||
createGeoDist, | ||
createGeoPos, | ||
createGeoHash, | ||
createGeoPos, | ||
createGet, | ||
createGetBit, | ||
createGetDel, | ||
|
@@ -129,7 +132,6 @@ import { | |
createZRevRank, | ||
createZRevRankWithScore, | ||
createZScore, | ||
GeoUnit, | ||
} from "./Commands"; | ||
import { BitOffsetOptions } from "./commands/BitOffsetOptions"; | ||
import { GeoAddOptions } from "./commands/geospatial/GeoAddOptions"; | ||
|
@@ -3330,6 +3332,63 @@ export class BaseClient { | |
return this.createWritePromise(createObjectRefcount(key)); | ||
} | ||
|
||
/** | ||
* Invokes a previously loaded function. | ||
* | ||
* See https://valkey.io/commands/fcall/ for more details. | ||
* | ||
* since Valkey version 7.0.0. | ||
* | ||
* @remarks When in cluster mode, all `keys` must map to the same hash slot. | ||
* @param func - The function name. | ||
* @param keys - A list of `keys` accessed by the function. To ensure the correct execution of functions, | ||
* all names of keys that a function accesses must be explicitly provided as `keys`. | ||
* @param args - A list of `function` arguments and it should not represent names of keys. | ||
* @returns The invoked function's return value. | ||
* | ||
* @example | ||
* ```typescript | ||
* const response = await client.fcall("Deep_Thought", [], []); | ||
* console.log(response); // Output: Returns the function's return value. | ||
* ``` | ||
*/ | ||
public fcall( | ||
func: string, | ||
keys: string[], | ||
args: string[], | ||
): Promise<string> { | ||
return this.createWritePromise(createFCall(func, keys, args)); | ||
} | ||
|
||
/** | ||
* Invokes a previously loaded read-only function. | ||
* | ||
* See https://valkey.io/commands/fcall/ for more details. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Valkey document currently doesn't list fcall_ro command. |
||
* | ||
* since Valkey version 7.0.0. | ||
* | ||
* @remarks When in cluster mode, all `keys` must map to the same hash slot. | ||
* @param func - The function name. | ||
* @param keys - A list of `keys` accessed by the function. To ensure the correct execution of functions, | ||
* all names of keys that a function accesses must be explicitly provided as `keys`. | ||
* @param args - A list of `function` arguments and it should not represent names of keys. | ||
* @returns The invoked function's return value. | ||
* | ||
* @example | ||
* ```typescript | ||
* const response = await client.fcallReadOnly("Deep_Thought", ["key1"], ["Answer", "to", "the", | ||
* "Ultimate", "Question", "of", "Life,", "the", "Universe,", "and", "Everything"]); | ||
* console.log(response); // Output: 42 # The return value on the function that was executed. | ||
* ``` | ||
*/ | ||
public fcallReadonly( | ||
func: string, | ||
keys: string[], | ||
args: string[], | ||
): Promise<string> { | ||
return this.createWritePromise(createFCallReadOnly(func, keys, args)); | ||
} | ||
|
||
/** | ||
* Returns the index of the first occurrence of `element` inside the list specified by `key`. If no | ||
* match is found, `null` is returned. If the `count` option is specified, then the function returns | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1584,6 +1584,32 @@ export function createBLPop( | |
return createCommand(RequestType.BLPop, args); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createFCall( | ||
func: string, | ||
keys: string[], | ||
args: string[], | ||
): command_request.Command { | ||
let params: string[] = []; | ||
params = params.concat(func, keys.length.toString(), keys, args); | ||
return createCommand(RequestType.FCall, params); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createFCallReadOnly( | ||
func: string, | ||
keys: string[], | ||
args: string[], | ||
): command_request.Command { | ||
let params: string[] = []; | ||
params = params.concat(func, keys.length.toString(), keys, args); | ||
return createCommand(RequestType.FCallReadOnly, params); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
|
@@ -1593,6 +1619,17 @@ export function createFunctionDelete( | |
return createCommand(RequestType.FunctionDelete, [libraryCode]); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createFunctionFlush(mode?: FlushMode): command_request.Command { | ||
if (mode) { | ||
return createCommand(RequestType.FunctionFlush, [mode.toString()]); | ||
} else { | ||
return createCommand(RequestType.FunctionFlush, []); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just group all function commands together. |
||
|
||
/** | ||
* @internal | ||
*/ | ||
|
@@ -1616,17 +1653,6 @@ export function createBitCount( | |
return createCommand(RequestType.BitCount, args); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createFunctionFlush(mode?: FlushMode): command_request.Command { | ||
if (mode) { | ||
return createCommand(RequestType.FunctionFlush, [mode.toString()]); | ||
} else { | ||
return createCommand(RequestType.FunctionFlush, []); | ||
} | ||
} | ||
|
||
export type StreamReadOptions = { | ||
/** | ||
* If set, the read request will block for the set amount of milliseconds or | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My VS Code automatically fix the order.