-
Notifications
You must be signed in to change notification settings - Fork 55
Support Triggers and Functions #145
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5aca820
strart working on RG commands
shacharPash 60b0375
delete interfaces
shacharPash 6f10c7b
test
shacharPash bf1aef6
Support TFunction Delete
shacharPash de2b95e
uncomment tests
shacharPash 018684b
fix test
shacharPash 1284fe7
fix tests
shacharPash 6da2318
Support TFunctionList
shacharPash 33c74e4
TestCommandBuilder
shacharPash 4c0d9dd
Support FTCall Sync
shacharPash 54bd84b
async FTCALL
shacharPash 9179584
Cleaning
shacharPash 71c9c3c
review fixes
shacharPash b929cb4
wip
shacharPash 63996db
Merge branch 'master' into SupportRG/Load
shacharPash 042e3f2
TryDeleteLib
shacharPash 8f1fbbc
Try to delete all optional libs before test and more fixes
shacharPash 5b18593
Merge branch 'master' into SupportRG/Load
shacharPash 6c84e09
fix test
shacharPash 704aa6d
use saved strings
shacharPash 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| using NRedisStack.RedisStackCommands; | ||
| using NRedisStack.Gears.Literals; | ||
| namespace NRedisStack | ||
| { | ||
|
|
||
| public static class GearsCommandBuilder | ||
| { | ||
| public static SerializedCommand TFunctionLoad(string libraryCode, bool replace = false, string? config = null) | ||
| { | ||
| var args = new List<object>() { GearsArgs.LOAD }; | ||
|
|
||
| if (replace) | ||
| { | ||
| args.Add(GearsArgs.REPLACE); | ||
| } | ||
|
|
||
| if (config != null) | ||
| { | ||
| args.Add(GearsArgs.CONFIG); | ||
| args.Add(config); | ||
| } | ||
| args.Add(libraryCode); | ||
| return new SerializedCommand(RG.TFUNCTION, args); | ||
| } | ||
|
|
||
| public static SerializedCommand TFunctionDelete(string libraryName) | ||
| { | ||
| return new SerializedCommand(RG.TFUNCTION, GearsArgs.DELETE, libraryName); | ||
| } | ||
|
|
||
| public static SerializedCommand TFunctionList(bool withCode = false, int verbose = 0, string? libraryName = null) | ||
| { | ||
| var args = new List<object>() { GearsArgs.LIST }; | ||
|
|
||
| if (withCode) | ||
| { | ||
| args.Add(GearsArgs.WITHCODE); | ||
| } | ||
|
|
||
| if (verbose > 0 && verbose < 4) | ||
| { | ||
| args.Add(new string('v', verbose)); | ||
| } | ||
| else if (verbose != 0) // verbose == 0 is the default so we don't need to throw an error | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(verbose), "verbose must be between 1 and 3"); | ||
| } | ||
|
|
||
| if (libraryName != null) | ||
| { | ||
| args.Add(GearsArgs.LIBRARY); | ||
| args.Add(libraryName); | ||
| } | ||
|
|
||
| return new SerializedCommand(RG.TFUNCTION, args); | ||
| } | ||
|
|
||
| public static SerializedCommand TFCall(string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false) | ||
| { | ||
| string command = async ? RG.TFCALLASYNC : RG.TFCALL; | ||
| var commandArgs = new List<object>() {$"{libraryName}.{functionName}"}; | ||
|
|
||
| if (keys != null) | ||
| { | ||
| commandArgs.Add(keys.Length); | ||
| commandArgs.AddRange(keys); | ||
| } | ||
| else | ||
| { | ||
| commandArgs.Add(0); | ||
| } | ||
|
|
||
| if (args != null) | ||
shacharPash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| commandArgs.AddRange(args); | ||
| } | ||
|
|
||
| return new SerializedCommand(command, commandArgs); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using StackExchange.Redis; | ||
| namespace NRedisStack | ||
| { | ||
|
|
||
| public static class GearsCommands //: GearsCommandsAsync, IGearsCommands | ||
| { | ||
|
|
||
| /// <summary> | ||
| /// Load a new library to RedisGears. | ||
| /// </summary> | ||
| /// <param name="libraryCode">the library code.</param> | ||
| /// <param name="config">a string representation of a JSON object | ||
| /// that will be provided to the library on load time, | ||
| /// for more information refer to | ||
| /// <see href="https://github.com/RedisGears/RedisGears/blob/master/docs/function_advance_topics.md#library-configuration"> | ||
| /// library configuration</see></param> | ||
| /// <param name="replace">an optional argument, instructs RedisGears to replace the function if its already exists.</param> | ||
| /// <returns><see langword="true"/> if everything was done correctly, Error otherwise.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/tfunction-load/"/></remarks> //TODO: check this link when it's available | ||
| public static bool TFunctionLoad(this IDatabase db, string libraryCode, bool replace = false, string? config = null) | ||
| { | ||
| return db.Execute(GearsCommandBuilder.TFunctionLoad(libraryCode, replace, config)).OKtoBoolean(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Delete a library from RedisGears. | ||
| /// </summary> | ||
| /// <param name="libraryName">the name of the library to delete.</param> | ||
| /// <returns><see langword="true"/> if the library was deleted successfully, Error otherwise.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/tfunction-delete/"/></remarks> //TODO: check this link when it's available | ||
| public static bool TFunctionDelete(this IDatabase db, string libraryName) | ||
| { | ||
| return db.Execute(GearsCommandBuilder.TFunctionDelete(libraryName)).OKtoBoolean(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// List the functions with additional information about each function. | ||
| /// </summary> | ||
| /// <param name="withCode">Show libraries code.</param> | ||
| /// <param name="verbose">output verbosity level, higher number will increase verbosity level</param> | ||
| /// <param name="libraryName">specifying a library name (can be used | ||
| /// multiple times to show multiple libraries in a single command)</param> | ||
| /// <returns>Information about the requested libraries.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/tfunction-list/"/></remarks> //TODO: check this link when it's available | ||
| public static Dictionary<string, RedisResult>[] TFunctionList(this IDatabase db, bool withCode = false, int verbose = 0, string? libraryName = null) | ||
| { | ||
| return db.Execute(GearsCommandBuilder.TFunctionList(withCode, verbose, libraryName)).ToDictionarys(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Trigger a sync or async (Coroutine) function. | ||
| /// </summary> | ||
| /// <param name="libraryName">The library name contains the function.</param> | ||
| /// <param name="functionName">The function name to run.</param> | ||
| /// <param name="keys">keys that will be touched by the function.</param> | ||
| /// <param name="args">Additional argument to pass to the function.</param> | ||
| /// <param name="async">If true, Invoke an async function (Coroutine).</param> | ||
| /// <returns>The return value from the sync & async function on error in case of failure.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/tfcall"/></remarks> //TODO: check this link when it's available | ||
| /// <remarks><seealso href="https://redis.io/commands/tfcallasync"/></remarks> //TODO: check this link when it's available | ||
| public static RedisResult TFCall(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false) | ||
| { | ||
| return db.Execute(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using StackExchange.Redis; | ||
| namespace NRedisStack | ||
| { | ||
|
|
||
| public static class GearsCommandsAsync //: IGearsCommandsAsync | ||
| { | ||
| /// <summary> | ||
| /// Load a new library to RedisGears. | ||
| /// </summary> | ||
| /// <param name="libraryCode">the library code.</param> | ||
| /// <param name="config">a string representation of a JSON object | ||
| /// that will be provided to the library on load time, | ||
| /// for more information refer to | ||
| /// <see href="https://github.com/RedisGears/RedisGears/blob/master/docs/function_advance_topics.md#library-configuration"> | ||
| /// library configuration</see></param> | ||
| /// <param name="replace">an optional argument, instructs RedisGears to replace the function if its already exists.</param> | ||
| /// <returns><see langword="true"/> if everything was done correctly, Error otherwise.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/"/></remarks> //TODO: add link to the command when it's available | ||
| public static async Task<bool> TFunctionLoadAsync(this IDatabase db, string libraryCode, string? config = null, bool replace = false) | ||
shacharPash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return (await db.ExecuteAsync(GearsCommandBuilder.TFunctionLoad(libraryCode, replace, config))).OKtoBoolean(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Delete a library from RedisGears. | ||
| /// </summary> | ||
| /// <param name="libraryName">the name of the library to delete.</param> | ||
| /// <returns><see langword="true"/> if the library was deleted successfully, Error otherwise.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/"/></remarks> //TODO: add link to the command when it's available | ||
| public static async Task<bool> TFunctionDeleteAsync(this IDatabase db, string libraryName) | ||
| { | ||
| return (await db.ExecuteAsync(GearsCommandBuilder.TFunctionDelete(libraryName))).OKtoBoolean(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// List the functions with additional information about each function. | ||
| /// </summary> | ||
| /// <param name="withCode">Show libraries code.</param> | ||
| /// <param name="verbose">output verbosity level, higher number will increase verbosity level</param> | ||
| /// <param name="libraryName">specifying a library name (can be used | ||
| /// multiple times to show multiple libraries in a single command)</param> | ||
| /// <returns>Information about the requested libraries.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/"/></remarks> //TODO: add link to the command when it's available | ||
| public static async Task<Dictionary<string, RedisResult>[]> TFunctionListAsync(this IDatabase db, bool withCode = false, int verbose = 0, string? libraryName = null) | ||
| { | ||
| return (await db.ExecuteAsync(GearsCommandBuilder.TFunctionList(withCode, verbose, libraryName))).ToDictionarys(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Invoke a sync or async (Coroutine) function. | ||
| /// </summary> | ||
| /// <param name="libraryName">The library name contains the function.</param> | ||
| /// <param name="functionName">The function name to run.</param> | ||
| /// <param name="keys">keys that will be touched by the function.</param> | ||
| /// <param name="args">Additional argument to pass to the function.</param> | ||
| /// <param name="async">If true, Invoke an async function (Coroutine).</param> | ||
| /// <returns>The return value from the sync & async function on error in case of failure.</returns> | ||
| /// <remarks><seealso href="https://redis.io/commands/"/></remarks> //TODO: add link to the command when it's available | ||
| public static async Task<RedisResult> TFCallAsync(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false) | ||
| { | ||
| return await db.ExecuteAsync(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace NRedisStack.Gears.Literals | ||
| { | ||
| internal class GearsArgs | ||
| { | ||
| public const string CONFIG = "CONFIG"; | ||
| public const string REPLACE = "REPLACE"; | ||
| public const string LOAD = "LOAD"; | ||
| public const string DELETE = "DELETE"; | ||
| public const string LIST = "LIST"; | ||
| public const string WITHCODE = "WITHCODE"; | ||
| public const string LIBRARY = "LIBRARY"; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace NRedisStack.Gears.Literals | ||
| { | ||
| /// <summary> | ||
| /// RedisGears command literals | ||
| /// </summary> | ||
| internal class RG | ||
| { | ||
| public const string TFUNCTION = "TFUNCTION"; | ||
| public const string TFCALL = "TFCALL"; | ||
| public const string TFCALLASYNC = "TFCALLASYNC"; | ||
| } | ||
| } |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.