-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add SCRIPT SHOW command #2171
Add SCRIPT SHOW command #2171
Changes from all commits
b06908e
d4cf84a
5e994a7
b667e6c
cb110a0
2176da8
d1b7c50
2737476
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3244,6 +3244,33 @@ public void invokeScript_gs_test(BaseClient client) { | |
} | ||
} | ||
|
||
@SneakyThrows | ||
@ParameterizedTest(autoCloseArguments = false) | ||
@MethodSource("getClients") | ||
public void scriptShow_test(BaseClient client) { | ||
assumeTrue(SERVER_VERSION.isGreaterThanOrEqualTo("7.9.0")); | ||
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. Why 7.9? Use 8.0 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. its release candidate so it would be changed when they will actually release it #2168 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. You can put version check 8.0 and tests start run on this version once everything implemented 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. or make it a constant we just need to update the constant when it's released. 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 have already added this before so it wont make any difference now 🙁 |
||
|
||
String code = "return '" + UUID.randomUUID().toString().substring(0, 5) + "'"; | ||
Script script = new Script(code, false); | ||
|
||
// Load the script | ||
client.invokeScript(script).get(); | ||
|
||
// Get the SHA1 digest of the script | ||
String sha1 = script.getHash(); | ||
|
||
// Test with String | ||
assertEquals(code, client.scriptShow(sha1).get()); | ||
|
||
// Test with GlideString | ||
assertEquals(gs(code), client.scriptShow(gs(sha1)).get()); | ||
|
||
// Test with non-existing SHA1 | ||
String nonExistingSha1 = UUID.randomUUID().toString(); | ||
assertThrows(ExecutionException.class, () -> client.scriptShow(nonExistingSha1).get()); | ||
assertThrows(ExecutionException.class, () -> client.scriptShow(gs(nonExistingSha1)).get()); | ||
} | ||
|
||
@SneakyThrows | ||
@ParameterizedTest(autoCloseArguments = false) | ||
@MethodSource("getClients") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,7 @@ import { | |
createSScan, | ||
createSUnion, | ||
createSUnionStore, | ||
createScriptShow, | ||
createSet, | ||
createSetBit, | ||
createSetRange, | ||
|
@@ -231,9 +232,9 @@ import { | |
ConfigurationError, | ||
ConnectionError, | ||
ExecAbortError, | ||
ValkeyError, | ||
RequestError, | ||
TimeoutError, | ||
ValkeyError, | ||
} from "./Errors"; | ||
import { GlideClientConfiguration } from "./GlideClient"; | ||
import { | ||
|
@@ -3695,6 +3696,31 @@ export class BaseClient { | |
return this.createWritePromise(scriptInvocation, options); | ||
} | ||
|
||
/** | ||
* Returns the original source code of a script in the script cache. | ||
* | ||
* @see {@link https://valkey.io/commands/script-show|valkey.io} for more details. | ||
* @remarks Since Valkey version 8.0.0. | ||
* | ||
* @param sha1 - The SHA1 digest of the script. | ||
* @param options - (Optional) See {@link DecoderOption}. | ||
* @return The original source code of the script, if present in the cache. | ||
* If the script is not found in the cache, an error is thrown. | ||
* | ||
* @example | ||
* ```typescript | ||
* const scriptHash = script.getHash(); | ||
* const scriptSource = await client.scriptShow(scriptHash); | ||
* console.log(scriptSource); // Output: "return { KEYS[1], ARGV[1] }" | ||
* ``` | ||
*/ | ||
public async scriptShow( | ||
sha1: GlideString, | ||
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. nit: is there a reason why we don't pass the Script object and internally we can call script.getHash()? 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. same as script exists, kill ect... 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. well... the comment could apply to any of these commands. 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 have no idea 🙉 |
||
options?: DecoderOption, | ||
): Promise<GlideString> { | ||
return this.createWritePromise(createScriptShow(sha1), options); | ||
} | ||
|
||
/** | ||
* Returns stream entries matching a given range of entry IDs. | ||
* | ||
|
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.
Does it return null if no script found? If yes, use another handler
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.
no it panics
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.
Oh right valkey-io/valkey#617
Should be added to the doc in all clients