|
| 1 | +using StackExchange.Redis; |
| 2 | +namespace NRedisStack |
| 3 | +{ |
| 4 | + |
| 5 | + public static class GearsCommands //: GearsCommandsAsync, IGearsCommands |
| 6 | + { |
| 7 | + |
| 8 | + /// <summary> |
| 9 | + /// Load a new library to RedisGears. |
| 10 | + /// </summary> |
| 11 | + /// <param name="libraryCode">the library code.</param> |
| 12 | + /// <param name="config">a string representation of a JSON object |
| 13 | + /// that will be provided to the library on load time, |
| 14 | + /// for more information refer to |
| 15 | + /// <see href="https://github.com/RedisGears/RedisGears/blob/master/docs/function_advance_topics.md#library-configuration"> |
| 16 | + /// library configuration</see></param> |
| 17 | + /// <param name="replace">an optional argument, instructs RedisGears to replace the function if its already exists.</param> |
| 18 | + /// <returns><see langword="true"/> if everything was done correctly, Error otherwise.</returns> |
| 19 | + /// <remarks><seealso href="https://redis.io/commands/tfunction-load/"/></remarks> //TODO: check this link when it's available |
| 20 | + public static bool TFunctionLoad(this IDatabase db, string libraryCode, bool replace = false, string? config = null) |
| 21 | + { |
| 22 | + return db.Execute(GearsCommandBuilder.TFunctionLoad(libraryCode, replace, config)).OKtoBoolean(); |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Delete a library from RedisGears. |
| 27 | + /// </summary> |
| 28 | + /// <param name="libraryName">the name of the library to delete.</param> |
| 29 | + /// <returns><see langword="true"/> if the library was deleted successfully, Error otherwise.</returns> |
| 30 | + /// <remarks><seealso href="https://redis.io/commands/tfunction-delete/"/></remarks> //TODO: check this link when it's available |
| 31 | + public static bool TFunctionDelete(this IDatabase db, string libraryName) |
| 32 | + { |
| 33 | + return db.Execute(GearsCommandBuilder.TFunctionDelete(libraryName)).OKtoBoolean(); |
| 34 | + } |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// List the functions with additional information about each function. |
| 38 | + /// </summary> |
| 39 | + /// <param name="withCode">Show libraries code.</param> |
| 40 | + /// <param name="verbose">output verbosity level, higher number will increase verbosity level</param> |
| 41 | + /// <param name="libraryName">specifying a library name (can be used |
| 42 | + /// multiple times to show multiple libraries in a single command)</param> |
| 43 | + /// <returns>Information about the requested libraries.</returns> |
| 44 | + /// <remarks><seealso href="https://redis.io/commands/tfunction-list/"/></remarks> //TODO: check this link when it's available |
| 45 | + public static Dictionary<string, RedisResult>[] TFunctionList(this IDatabase db, bool withCode = false, int verbose = 0, string? libraryName = null) |
| 46 | + { |
| 47 | + return db.Execute(GearsCommandBuilder.TFunctionList(withCode, verbose, libraryName)).ToDictionarys(); |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Trigger a sync or async (Coroutine) function. |
| 52 | + /// </summary> |
| 53 | + /// <param name="libraryName">The library name contains the function.</param> |
| 54 | + /// <param name="functionName">The function name to run.</param> |
| 55 | + /// <param name="keys">keys that will be touched by the function.</param> |
| 56 | + /// <param name="args">Additional argument to pass to the function.</param> |
| 57 | + /// <param name="async">If true, Invoke an async function (Coroutine).</param> |
| 58 | + /// <returns>The return value from the sync & async function on error in case of failure.</returns> |
| 59 | + /// <remarks><seealso href="https://redis.io/commands/tfcall"/></remarks> //TODO: check this link when it's available |
| 60 | + /// <remarks><seealso href="https://redis.io/commands/tfcallasync"/></remarks> //TODO: check this link when it's available |
| 61 | + public static RedisResult TFCall(this IDatabase db, string libraryName, string functionName, string[]? keys = null, string[]? args = null, bool async = false) |
| 62 | + { |
| 63 | + return db.Execute(GearsCommandBuilder.TFCall(libraryName, functionName, keys, args, async)); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments